Skip to content

Commit

Permalink
improve ms-sse-fetch to not re-fetch automatially
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat committed Dec 6, 2023
1 parent 79cdb86 commit ef79649
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/src/models/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Workspace = {
body: JSON.stringify({ message, mode }),
headers: baseHeaders(),
signal: ctrl.signal,
openWhenHidden: true,
async onopen(response) {
if (response.ok) {
return; // everything's good
Expand All @@ -74,8 +75,26 @@ const Workspace = {
response.status < 500 &&
response.status !== 429
) {
handleChat({
id: v4(),
type: "abort",
textResponse: null,
sources: [],
close: true,
error: `An error occurred while streaming response. Code ${response.status}`,
});
ctrl.abort();
throw new Error("Invalid Status code response.");
} else {
handleChat({
id: v4(),
type: "abort",
textResponse: null,
sources: [],
close: true,
error: `An error occurred while streaming response. Unknown Error.`,
});
ctrl.abort();
throw new Error("Unknown error");
}
},
Expand All @@ -95,6 +114,7 @@ const Workspace = {
error: `An error occurred while streaming response. ${err.message}`,
});
ctrl.abort();
throw new Error();
},
});
},
Expand Down

0 comments on commit ef79649

Please sign in to comment.