From 0ea683ad811f7cceea74034a38592fc6bf20dee9 Mon Sep 17 00:00:00 2001 From: Elliott <85990359+Ell1ott@users.noreply.github.com> Date: Fri, 23 Feb 2024 22:51:26 +0100 Subject: [PATCH 1/4] Create API down ui --- src/lib/api/apiStore.ts | 3 +++ src/lib/api/index.ts | 13 +++++++++++-- src/lib/components/ApiDown.svelte | 23 +++++++++++++++++++++++ src/routes/workspace/Workspace.svelte | 3 +++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/ApiDown.svelte diff --git a/src/lib/api/apiStore.ts b/src/lib/api/apiStore.ts index 04877407..0a2edf42 100644 --- a/src/lib/api/apiStore.ts +++ b/src/lib/api/apiStore.ts @@ -30,6 +30,7 @@ export interface Assignment { } export async function updateFiles() { + console.log('will try to update files'); const api = getContext('api') as ApiHandler; const userDocuments = await api.getUserDocuments(); @@ -74,3 +75,5 @@ export async function updateAssignments() { assignmentStore.set(json); console.log('updated assignments', json); } + +export const apiDownStore = writable(false); diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 6cfc5133..1edd1748 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -1,5 +1,6 @@ import type { AuthorizerState } from 'akademia-authorizer-svelte/types'; import { get, type Readable } from 'svelte/store'; +import { apiDownStore } from './apiStore'; export default class ApiHandler { static baseUrl = 'https://akademia-api.arctix.dev'; @@ -44,7 +45,15 @@ export default class ApiHandler { method, headers } - ); + ).catch((error) => { + // Handle CORS-related errors + if (error.name === 'TypeError' && error.message.includes('Failed to fetch')) { + console.log('API seems to be down at the moment'); + apiDownStore.set(true); + } else { + console.error('Other error:', error); + } + }); } getDocument = (documentId: string) => { @@ -53,7 +62,7 @@ export default class ApiHandler { getDocumentJson = (documentId: string) => { return this.callApi('/documents/' + documentId + '/json'); - } + }; getUserDocuments = () => { return this.callApi('/documents'); diff --git a/src/lib/components/ApiDown.svelte b/src/lib/components/ApiDown.svelte new file mode 100644 index 00000000..9b721482 --- /dev/null +++ b/src/lib/components/ApiDown.svelte @@ -0,0 +1,23 @@ + + + + + Oops! ser ud til at API'en er nede + Det ser ud til, at vores API har besluttet at tage en kaffe-pause og lade vores udviklere + arbejde deres magi bag kulisserne! Vi undskylder for besværet og lover at få det op at køre + igen snarest muligt. +
+ + +
+
+
diff --git a/src/routes/workspace/Workspace.svelte b/src/routes/workspace/Workspace.svelte index 22140117..a37bdf4d 100644 --- a/src/routes/workspace/Workspace.svelte +++ b/src/routes/workspace/Workspace.svelte @@ -7,6 +7,7 @@ import { updateFiles, updateUserInfo, updateAssignments } from '@/api/apiStore'; import ApiHandler from '@/api'; import SidebarAssignment from './SidebarAssignment.svelte'; + import ApiDown from '@/components/ApiDown.svelte'; let state: AuthorizerState; @@ -46,6 +47,8 @@ + + diff --git a/src/routes/workspace/FileViewer.svelte b/src/routes/workspace/FileViewer.svelte index 4a3a8e39..b0279345 100644 --- a/src/routes/workspace/FileViewer.svelte +++ b/src/routes/workspace/FileViewer.svelte @@ -35,7 +35,10 @@