Skip to content

Commit 8601599

Browse files
authored
MessageSuggestions: custom error handling #66
add an optional `handleError` prop, similar to the other components (ChatInput, ChatPanel, etc.) for custom error handling, which will override the default handling (console log + "sorry I can't help" message) will publish a new version on merge J=CLIP-1052 TEST=auto see that jest tests passed
1 parent 099bcd1 commit 8601599

15 files changed

+84
-23
lines changed

docs/chat-ui-react.messagesuggestionsprops.customcssclasses.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## MessageSuggestionsProps.customCssClasses property
66

7+
CSS classes for customizing the component styling.
8+
79
**Signature:**
810

911
```typescript
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@yext/chat-ui-react](./chat-ui-react.md) &gt; [MessageSuggestionsProps](./chat-ui-react.messagesuggestionsprops.md) &gt; [handleError](./chat-ui-react.messagesuggestionsprops.handleerror.md)
4+
5+
## MessageSuggestionsProps.handleError property
6+
7+
A function which is called when an error occurs from Chat API while processing the user's message. By default, the error is logged to the console and an error message is added to state.
8+
9+
**Signature:**
10+
11+
```typescript
12+
handleError?: (e: unknown) => void;
13+
```

docs/chat-ui-react.messagesuggestionsprops.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface MessageSuggestionsProps
1616

1717
| Property | Modifiers | Type | Description |
1818
| --- | --- | --- | --- |
19-
| [customCssClasses?](./chat-ui-react.messagesuggestionsprops.customcssclasses.md) | | [MessageSuggestionCssClasses](./chat-ui-react.messagesuggestioncssclasses.md) | _(Optional)_ |
20-
| [suggestions](./chat-ui-react.messagesuggestionsprops.suggestions.md) | | string\[\] | |
19+
| [customCssClasses?](./chat-ui-react.messagesuggestionsprops.customcssclasses.md) | | [MessageSuggestionCssClasses](./chat-ui-react.messagesuggestioncssclasses.md) | _(Optional)_ CSS classes for customizing the component styling. |
20+
| [handleError?](./chat-ui-react.messagesuggestionsprops.handleerror.md) | | (e: unknown) =&gt; void | _(Optional)_ A function which is called when an error occurs from Chat API while processing the user's message. By default, the error is logged to the console and an error message is added to state. |
21+
| [suggestions](./chat-ui-react.messagesuggestionsprops.suggestions.md) | | string\[\] | List of clickable message suggestions to render. |
2122

docs/chat-ui-react.messagesuggestionsprops.suggestions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## MessageSuggestionsProps.suggestions property
66

7+
List of clickable message suggestions to render.
8+
79
**Signature:**
810

911
```typescript

etc/chat-ui-react.api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ export interface MessageSuggestionCssClasses {
228228

229229
// @public
230230
export interface MessageSuggestionsProps {
231-
// (undocumented)
232231
customCssClasses?: MessageSuggestionCssClasses;
233-
// (undocumented)
232+
handleError?: (e: unknown) => void;
234233
suggestions: string[];
235234
}
236235

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yext/chat-ui-react",
3-
"version": "0.8.7",
3+
"version": "0.8.8",
44
"description": "A library of React Components for powering Yext Chat integrations.",
55
"author": "clippy@yext.com",
66
"main": "./lib/commonjs/src/index.js",

src/components/ChatInput.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ export function ChatInput({
9494
? chat.streamNextMessage(input)
9595
: chat.getNextMessage(input);
9696
setInput("");
97-
res.then(() => {
98-
onSend?.(input)
99-
}).catch((e) => (handleError ? handleError(e) : defaultHandleApiError(e)));
97+
res
98+
.then(() => {
99+
onSend?.(input);
100+
})
101+
.catch((e) => (handleError ? handleError(e) : defaultHandleApiError(e)));
100102
}, [chat, input, handleError, defaultHandleApiError, stream, onSend]);
101103

102104
const handleKeyDown = useCallback(

src/components/ChatPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export function ChatPanel(props: ChatPanelProps) {
180180
<div className={cssClasses.inputContainer}>
181181
{suggestions && (
182182
<MessageSuggestions
183+
handleError={handleError}
183184
suggestions={suggestions}
184185
customCssClasses={cssClasses.messageSuggestionClasses}
185186
/>

src/components/Markdown.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function Markdown({
7878
responseId,
7979
},
8080
});
81-
onLinkClick?.(href)
81+
onLinkClick?.(href);
8282
};
8383
return {
8484
a: ({ node: _, children, ...props }) => {
@@ -95,7 +95,13 @@ export function Markdown({
9595
);
9696
},
9797
};
98-
}, [reportAnalyticsEvent, linkClickEvent, responseId, cssClasses, onLinkClick]);
98+
}, [
99+
reportAnalyticsEvent,
100+
linkClickEvent,
101+
responseId,
102+
cssClasses,
103+
onLinkClick,
104+
]);
99105

100106
return (
101107
<ReactMarkdown

0 commit comments

Comments
 (0)