From 5262156c248394a9e544eb0fe22b5e769970ae61 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 13 Dec 2023 13:05:31 -0800 Subject: [PATCH] feat: error handling for when ollama is not running --- src/routes/(app)/+page.svelte | 25 ++++++++++++++++--------- src/routes/(app)/c/[id]/+page.svelte | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index e7d522b1c..f6bf0e350 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -189,17 +189,12 @@ }, format: $settings.requestFormat ?? undefined }) + }).catch((err) => { + console.log(err); + return null; }); - if (!res.ok) { - const error = await res.json(); - console.log(error); - if ('detail' in error) { - toast.error(error.detail); - } else { - toast.error(error.error); - } - } else { + if (res && res.ok) { const reader = res.body .pipeThrough(new TextDecoderStream()) .pipeThrough(splitStream('\n')) @@ -275,6 +270,18 @@ history: history }); } + } else { + if (res !== null) { + const error = await res.json(); + console.log(error); + if ('detail' in error) { + toast.error(error.detail); + } else { + toast.error(error.error); + } + } else { + toast.error(`Uh-oh! There was an issue connecting to Ollama.`); + } } stopResponseFlag = false; diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index ff2a9b17a..3eec7a5e9 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -216,17 +216,12 @@ }, format: $settings.requestFormat ?? undefined }) + }).catch((err) => { + console.log(err); + return null; }); - if (!res.ok) { - const error = await res.json(); - console.log(error); - if ('detail' in error) { - toast.error(error.detail); - } else { - toast.error(error.error); - } - } else { + if (res && res.ok) { const reader = res.body .pipeThrough(new TextDecoderStream()) .pipeThrough(splitStream('\n')) @@ -302,6 +297,18 @@ history: history }); } + } else { + if (res !== null) { + const error = await res.json(); + console.log(error); + if ('detail' in error) { + toast.error(error.detail); + } else { + toast.error(error.error); + } + } else { + toast.error(`Uh-oh! There was an issue connecting to Ollama.`); + } } stopResponseFlag = false;