error page
This commit is contained in:
19
webapp/src/routes/__error.svelte
Normal file
19
webapp/src/routes/__error.svelte
Normal file
@@ -0,0 +1,19 @@
|
||||
<script context="module" lang="ts">
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
|
||||
export const load: Load = ({ error, status }) => {
|
||||
return {
|
||||
props: {
|
||||
title: `${status}: ${error?.message}`
|
||||
}
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let title: string;
|
||||
</script>
|
||||
|
||||
<div class="prose max-w-2xl">
|
||||
<h1>{title}</h1>
|
||||
</div>
|
||||
@@ -5,14 +5,27 @@
|
||||
export const load: Load = async ({ params, fetch, session, stuff }) => {
|
||||
const url = `${import.meta.env.VITE_BACKEND_URL}/note/${params.id}`;
|
||||
const response = await fetch(url);
|
||||
const note: EncryptedNote = await response.json();
|
||||
|
||||
note.insert_time = new Date(note.insert_time as unknown as string);
|
||||
|
||||
return {
|
||||
status: response.status,
|
||||
props: { note }
|
||||
};
|
||||
if (response.ok) {
|
||||
try {
|
||||
const note: EncryptedNote = await response.json();
|
||||
note.insert_time = new Date(note.insert_time as unknown as string);
|
||||
return {
|
||||
status: response.status,
|
||||
props: { note }
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
status: 500,
|
||||
error: response.statusText
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
status: response.status,
|
||||
error: response.statusText
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user