From 232b36d4ae7d349b98f64f6cdb32bd92f10ec92c Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Fri, 23 Aug 2024 17:58:57 +0530 Subject: [PATCH] fix: sync with the error handling --- .../src/components/DocsGPTWidget.tsx | 22 ++++++++++++------- .../react-widget/src/requests/streamingApi.ts | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/extensions/react-widget/src/components/DocsGPTWidget.tsx b/extensions/react-widget/src/components/DocsGPTWidget.tsx index 30a292ef..a6228a15 100644 --- a/extensions/react-widget/src/components/DocsGPTWidget.tsx +++ b/extensions/react-widget/src/components/DocsGPTWidget.tsx @@ -83,7 +83,7 @@ const StyledContainer = styled.div` box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.1); transition: visibility 0.3s, opacity 0.3s; `; -const FloatingButton = styled.div<{bg:string}>` +const FloatingButton = styled.div<{ bg: string }>` position: fixed; display: flex; z-index: 500; @@ -366,12 +366,18 @@ export const DocsGPTWidget = ({ const data = JSON.parse(event.data); // check if the 'end' event has been received if (data.type === 'end') { - // set status to 'idle' setStatus('idle'); - - } else if (data.type === 'id') { + } + else if (data.type === 'id') { setConversationId(data.id) - } else { + } + else if (data.type === 'error') { + const updatedQueries = [...queries]; + updatedQueries[updatedQueries.length - 1].error = data.error; + setQueries(updatedQueries); + setStatus('idle') + } + else { const result = data.answer; const streamingResponse = queries[queries.length - 1].response ? queries[queries.length - 1].response : ''; const updatedQueries = [...queries]; @@ -383,7 +389,7 @@ export const DocsGPTWidget = ({ ); } catch (error) { const updatedQueries = [...queries]; - updatedQueries[updatedQueries.length - 1].error = 'error' + updatedQueries[updatedQueries.length - 1].error = 'Something went wrong !' setQueries(updatedQueries); setStatus('idle') //setEventInterrupt(false) @@ -407,7 +413,7 @@ export const DocsGPTWidget = ({ {!open && setOpen(true)} hidden={open}> - + } {open &&
@@ -455,7 +461,7 @@ export const DocsGPTWidget = ({
Network Error
- Something went wrong ! + {query.error}
: diff --git a/extensions/react-widget/src/requests/streamingApi.ts b/extensions/react-widget/src/requests/streamingApi.ts index cea339b9..b594915f 100644 --- a/extensions/react-widget/src/requests/streamingApi.ts +++ b/extensions/react-widget/src/requests/streamingApi.ts @@ -25,7 +25,7 @@ export function fetchAnswerStreaming({ history: JSON.stringify(history), conversation_id: conversationId, model: 'default', - apiKey:apiKey + api_key:apiKey }; fetch(apiHost + '/stream', { method: 'POST',