Skip to content
Snippets Groups Projects
Commit ef796498 authored by timothycarambat's avatar timothycarambat
Browse files

improve ms-sse-fetch to not re-fetch automatially

...@@ -66,6 +66,7 @@ const Workspace = { ...@@ -66,6 +66,7 @@ const Workspace = {
body: JSON.stringify({ message, mode }), body: JSON.stringify({ message, mode }),
headers: baseHeaders(), headers: baseHeaders(),
signal: ctrl.signal, signal: ctrl.signal,
openWhenHidden: true,
async onopen(response) { async onopen(response) {
if (response.ok) { if (response.ok) {
return; // everything's good return; // everything's good
...@@ -74,8 +75,26 @@ const Workspace = { ...@@ -74,8 +75,26 @@ const Workspace = {
response.status < 500 && response.status < 500 &&
response.status !== 429 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."); throw new Error("Invalid Status code response.");
} else { } 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"); throw new Error("Unknown error");
} }
}, },
...@@ -95,6 +114,7 @@ const Workspace = { ...@@ -95,6 +114,7 @@ const Workspace = {
error: `An error occurred while streaming response. ${err.message}`, error: `An error occurred while streaming response. ${err.message}`,
}); });
ctrl.abort(); ctrl.abort();
throw new Error();
}, },
}); });
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment