From b89b1d11e3c4c3c4f6e1ab9552a7924263026013 Mon Sep 17 00:00:00 2001 From: Eamon O'Reilly Date: Fri, 14 Jun 2024 14:53:26 -0700 Subject: [PATCH] Create new chat if chat history table does not exist --- app/frontend/src/api/api.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/frontend/src/api/api.ts b/app/frontend/src/api/api.ts index 6eb2592..d0e32a0 100644 --- a/app/frontend/src/api/api.ts +++ b/app/frontend/src/api/api.ts @@ -76,11 +76,18 @@ export async function getUserId(): Promise { const chatHistoryResponse = await fetch('/api/chat/' + globalThis.assistantId + '?timestampUTC=2023-01-01T00:00:00Z', { method: "GET",}); - const chatHistory = await chatHistoryResponse.json(); - - // If no chat history, create a new chat - if (chatHistory.answer == "No response returned.") { - newChat(globalThis.assistantId); + // Create a new chat if the chat table does not exist - results in an error + if (chatHistoryResponse.status > 299 || !chatHistoryResponse.ok) { + newChat(globalThis.assistantId + ); + } + else + { + // If no chat history, create a new chat + const chatHistory = await chatHistoryResponse.json(); + if (chatHistory.answer == "No response returned.") { + newChat(globalThis.assistantId); + } } return clientPrincipal.userId }