From ef796498912e71aa02a83bb7a98edccb66f83793 Mon Sep 17 00:00:00 2001
From: timothycarambat <rambat1010@gmail.com>
Date: Wed, 6 Dec 2023 12:04:10 -0800
Subject: [PATCH] improve ms-sse-fetch to not re-fetch automatially

---
 frontend/src/models/workspace.js | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/frontend/src/models/workspace.js b/frontend/src/models/workspace.js
index fc54e9147..2990e5541 100644
--- a/frontend/src/models/workspace.js
+++ b/frontend/src/models/workspace.js
@@ -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
@@ -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");
         }
       },
@@ -95,6 +114,7 @@ const Workspace = {
           error: `An error occurred while streaming response. ${err.message}`,
         });
         ctrl.abort();
+        throw new Error();
       },
     });
   },
-- 
GitLab