Skip to content

Commit 8a5c4c8

Browse files
authored
frontend: Add special handling for HTTP errors when trying to begin a streaming chat (#873)
* Add special handling for HTTP errors when trying to begin a streaming chat * Fix formatting * Fix build * Fix build * Apply the improved stream error handling to Coral
1 parent 11d3e25 commit 8a5c4c8

File tree

6 files changed

+536
-538
lines changed

6 files changed

+536
-538
lines changed

src/interfaces/assistants_web/src/cohere-client/client.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,24 @@ export class CohereClient {
134134
body: requestBody,
135135
signal,
136136
openWhenHidden: true, // When false, the requests will be paused when the tab is hidden and resume/retry when the tab is visible again
137-
onopen: onOpen,
137+
onopen: async (response: Response) => {
138+
if (
139+
response.status !== 200 &&
140+
response.headers.get('content-type')?.includes('application/json')
141+
) {
142+
await response
143+
.json()
144+
.catch((e) => {
145+
throw new CohereNetworkError('Failed to decode error message JSON', response.status);
146+
})
147+
.then((data) => {
148+
throw new CohereNetworkError(data.detail, response.status);
149+
});
150+
}
151+
if (onOpen) {
152+
onOpen(response);
153+
}
154+
},
138155
onmessage: onMessage,
139156
onclose: onClose,
140157
onerror: onError,

src/interfaces/assistants_web/src/components/MessageRow/MessageContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const MessageContent: React.FC<Props> = ({ isLast, message, onRetry }) =>
3939
<MessageInfo type="error">
4040
{message.error}
4141
{isLast && (
42-
<button className="underline underline-offset-1" type="button" onClick={onRetry}>
42+
<button className="ml-2 underline underline-offset-1" type="button" onClick={onRetry}>
4343
Retry?
4444
</button>
4545
)}

0 commit comments

Comments
 (0)