From 8472d54524d79ff91249302ae2959c209c9ee7ac Mon Sep 17 00:00:00 2001 From: Emil Kowalski <36730035+emilkowalski@users.noreply.github.com> Date: Fri, 10 Nov 2023 03:09:33 +0100 Subject: [PATCH] Account for fetch in promise (#223) * Account for fetch in promise * Clenaup --- src/state.ts | 14 +++++++++++--- website/src/components/Types/Types.tsx | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/state.ts b/src/state.ts index 344b7f1..89e8df1 100644 --- a/src/state.ts +++ b/src/state.ts @@ -123,10 +123,18 @@ class Observer { let shouldDismiss = id !== undefined; - p.then((promiseData) => { - if (data.success !== undefined) { + p.then((response) => { + // TODO: Clean up TS here, response has incorrect type + // @ts-expect-error + if (response && typeof response.ok === 'boolean' && !response.ok) { shouldDismiss = false; - const message = typeof data.success === 'function' ? data.success(promiseData) : data.success; + const message = + // @ts-expect-error + typeof data.error === 'function' ? data.error(`HTTP error! status: ${response.status}`) : data.error; + this.create({ id, type: 'error', message }); + } else if (data.success !== undefined) { + shouldDismiss = false; + const message = typeof data.success === 'function' ? data.success(response) : data.success; this.create({ id, type: 'success', message }); } }) diff --git a/website/src/components/Types/Types.tsx b/website/src/components/Types/Types.tsx index a3fef38..8f1b0e3 100644 --- a/website/src/components/Types/Types.tsx +++ b/website/src/components/Types/Types.tsx @@ -114,6 +114,6 @@ toast.promise(promise, { { name: 'Custom', snippet: `toast(