Skip to content

Commit

Permalink
frontend: Add special handling for HTTP errors when trying to begin a…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
malexw authored Dec 20, 2024
1 parent 11d3e25 commit 8a5c4c8
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 538 deletions.
19 changes: 18 additions & 1 deletion src/interfaces/assistants_web/src/cohere-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,24 @@ export class CohereClient {
body: requestBody,
signal,
openWhenHidden: true, // When false, the requests will be paused when the tab is hidden and resume/retry when the tab is visible again
onopen: onOpen,
onopen: async (response: Response) => {
if (
response.status !== 200 &&
response.headers.get('content-type')?.includes('application/json')
) {
await response
.json()
.catch((e) => {
throw new CohereNetworkError('Failed to decode error message JSON', response.status);
})
.then((data) => {
throw new CohereNetworkError(data.detail, response.status);
});
}
if (onOpen) {
onOpen(response);
}
},
onmessage: onMessage,
onclose: onClose,
onerror: onError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const MessageContent: React.FC<Props> = ({ isLast, message, onRetry }) =>
<MessageInfo type="error">
{message.error}
{isLast && (
<button className="underline underline-offset-1" type="button" onClick={onRetry}>
<button className="ml-2 underline underline-offset-1" type="button" onClick={onRetry}>
Retry?
</button>
)}
Expand Down
Loading

0 comments on commit 8a5c4c8

Please sign in to comment.