From f8338c67541b47afafa8228a4d47ee63c7f8a348 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Fri, 16 Aug 2024 20:00:42 -0400 Subject: [PATCH] Wikipedia error handling --- frontend/src/lib/components/EditAdventure.svelte | 10 ++++++++++ frontend/src/lib/components/NewAdventure.svelte | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/frontend/src/lib/components/EditAdventure.svelte b/frontend/src/lib/components/EditAdventure.svelte index d772531..6654fba 100644 --- a/frontend/src/lib/components/EditAdventure.svelte +++ b/frontend/src/lib/components/EditAdventure.svelte @@ -16,6 +16,7 @@ let isPointModalOpen: boolean = false; let isImageFetcherOpen: boolean = false; + let wikiError: string = ''; let fileInput: HTMLInputElement; let image: File; @@ -55,8 +56,14 @@ async function generateDesc() { let res = await fetch(`/api/generate/desc/?name=${adventureToEdit.name}`); let data = await res.json(); + if (!res.ok) { + wikiError = 'No article found'; + } if (data.extract) { + wikiError = ''; adventureToEdit.description = data.extract; + } else { + wikiError = 'No description found'; } } @@ -226,6 +233,9 @@ >Generate Description + {#if wikiError} +

{wikiError}

+ {/if} {#if adventureToEdit.type == 'visited' || adventureToEdit.type == 'planned'}
diff --git a/frontend/src/lib/components/NewAdventure.svelte b/frontend/src/lib/components/NewAdventure.svelte index 6801b5a..4f114f7 100644 --- a/frontend/src/lib/components/NewAdventure.svelte +++ b/frontend/src/lib/components/NewAdventure.svelte @@ -28,6 +28,8 @@ export let startDate: string | null = null; export let endDate: string | null = null; + let wikiError: string = ''; + let newAdventure: Adventure = { id: '', type: type, @@ -105,8 +107,14 @@ async function generateDesc() { let res = await fetch(`/api/generate/desc/?name=${newAdventure.name}`); let data = await res.json(); + if (!res.ok) { + wikiError = 'No article found'; + } if (data.extract) { + wikiError = ''; newAdventure.description = data.extract; + } else { + wikiError = 'No description found'; } } @@ -307,6 +315,9 @@ >Generate Description
+ {#if wikiError} +

{wikiError}

+ {/if} {#if newAdventure.type == 'visited' || newAdventure.type == 'planned'}