Skip to content

Commit e288126

Browse files
committed
Improve error handling
1 parent 56943b0 commit e288126

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/components/Messages/style.module.css

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.messagesContainer {
2+
position: relative;
23
display: flex;
34
flex-direction: column;
45
flex-grow: 1;
@@ -8,16 +9,26 @@
89
scrollbar-color: var(--clover-ai-colors-secondaryAlt) transparent;
910
overflow-y: scroll;
1011

12+
&::after {
13+
font-style: italic;
14+
--line-height: 1.5;
15+
line-height: var(--line-height);
16+
/* The multiplier -2 is used to adjust the positioning of the content text
17+
relative to the preceding content. It ensures the text appears slightly above
18+
its default position for better visual alignment. */
19+
margin-block-start: calc(-2 * (var(--line-height) * var(--clover-ai-sizes-3)));
20+
}
21+
1122
&[data-state="assistant_responding"] {
1223
&::after {
1324
content: "Thinking...";
14-
font-style: italic;
15-
--line-height: 1.5;
16-
line-height: var(--line-height);
17-
/* The multiplier -2 is used to adjust the positioning of the "Thinking..." text
18-
relative to the preceding content. It ensures the text appears slightly above
19-
its default position for better visual alignment. */
20-
margin-block-start: calc(-2 * (var(--line-height) * var(--clover-ai-sizes-3)));
25+
}
26+
}
27+
28+
&[data-state="error"] {
29+
&::after {
30+
content: "An error occurred. Please try again.";
31+
color: var(--clover-ai-colors-error);
2132
}
2233
}
2334

src/components/TextArea/index.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ type ContentEditableProps = ComponentProps<typeof ContentEditable>;
88
export interface TextareaProps extends ContentEditableProps {
99
label?: string;
1010
labelDisplay?: "hidden" | "visible";
11+
/** An error message to display to the user */
1112
error?: string;
12-
helperText?: string;
13-
variant?: "default" | "bordered" | "filled";
1413
size?: "small" | "medium" | "large";
1514
id?: string;
1615
children?: React.ReactNode;
@@ -20,18 +19,15 @@ export const Textarea: FC<TextareaProps> = ({
2019
label,
2120
labelDisplay = "visible",
2221
error,
23-
helperText,
24-
variant = "default",
2522
size = "medium",
2623
children,
2724
...rest
2825
}) => {
2926
const textareaId = `textarea-contenteditable-container`;
3027
const labelId = `textarea-label`;
31-
const helperId = `textarea-helper`;
3228

3329
return (
34-
<div className={styles.container}>
30+
<div className={styles.container} data-error={!!error}>
3531
{label && (
3632
<label
3733
className={labelDisplay === "hidden" ? styles.visuallyHidden : styles.label}
@@ -43,12 +39,9 @@ export const Textarea: FC<TextareaProps> = ({
4339
</label>
4440
)}
4541
<div
46-
aria-describedby={helperId}
4742
aria-labelledby={label ? labelId : undefined}
4843
className={styles.textarea}
49-
data-error={!!error}
5044
data-size={size}
51-
data-variant={variant}
5245
id={textareaId}
5346
>
5447
<ContentEditable
@@ -60,9 +53,9 @@ export const Textarea: FC<TextareaProps> = ({
6053
/>
6154
{children && <div className={styles.childrenContainer}>{children}</div>}
6255
</div>
63-
{(error || helperText) && (
64-
<div className={styles.helperText} data-error={!!error} id={helperId}>
65-
{error || helperText}
56+
{error && (
57+
<div className={styles.errorMessage} aria-live="polite">
58+
{error}
6659
</div>
6760
)}
6861
</div>

src/providers/userTokenProvider/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class UserTokenProvider extends BaseProvider {
232232

233233
this.set_conversation_state("idle");
234234
} catch (error) {
235-
console.error("Error sending messages:", error); // eslint-disable-line no-console
235+
console.error(error); // eslint-disable-line no-console
236236
this.set_conversation_state("error");
237237
}
238238
}

0 commit comments

Comments
 (0)