Skip to content

Commit

Permalink
Wikipedia error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 committed Aug 17, 2024
1 parent 15cca42 commit f8338c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions frontend/src/lib/components/EditAdventure.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
let isPointModalOpen: boolean = false;
let isImageFetcherOpen: boolean = false;
let wikiError: string = '';
let fileInput: HTMLInputElement;
let image: File;
Expand Down Expand Up @@ -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';
}
}
Expand Down Expand Up @@ -226,6 +233,9 @@
><Wikipedia class="inline-block -mt-1 mb-1 w-6 h-6" />Generate Description</button
>
</div>
{#if wikiError}
<p class="text-red-500">{wikiError}</p>
{/if}
</div>
{#if adventureToEdit.type == 'visited' || adventureToEdit.type == 'planned'}
<div class="mb-2">
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/lib/components/NewAdventure.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
}
}
Expand Down Expand Up @@ -307,6 +315,9 @@
><Wikipedia class="inline-block -mt-1 mb-1 w-6 h-6" />Generate Description</button
>
</div>
{#if wikiError}
<p class="text-red-500">{wikiError}</p>
{/if}
</div>
{#if newAdventure.type == 'visited' || newAdventure.type == 'planned'}
<div class="mb-2">
Expand Down

0 comments on commit f8338c6

Please sign in to comment.