diff --git a/src/app.d.ts b/src/app.d.ts new file mode 100644 index 000000000..fea14bd33 --- /dev/null +++ b/src/app.d.ts @@ -0,0 +1,9 @@ +declare global { + namespace App { + interface Error { + code?: string; + } + } +} + +export {}; diff --git a/src/error.html b/src/error.html new file mode 100644 index 000000000..930769276 --- /dev/null +++ b/src/error.html @@ -0,0 +1,13 @@ + + +
+ +Status: %sveltekit.status%
+Message: %sveltekit.error.message%
+ + diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte index 7b184c63b..ee6149e32 100644 --- a/src/routes/+error.svelte +++ b/src/routes/+error.svelte @@ -2,4 +2,6 @@ import { page } from '$app/stores'; + +{JSON.stringify($page.error, null, 2)}diff --git a/src/routes/[network]/(explorer)/account/[name]/+layout.ts b/src/routes/[network]/(explorer)/account/[name]/+layout.ts index 7f6a94cb6..66ccab7bc 100644 --- a/src/routes/[network]/(explorer)/account/[name]/+layout.ts +++ b/src/routes/[network]/(explorer)/account/[name]/+layout.ts @@ -1,10 +1,16 @@ import { AccountState } from '$lib/state/client/account.svelte'; import { getNetworkFromParams } from '$lib/state/network.svelte'; -import type { LoadEvent } from '@sveltejs/kit'; +import { error, type LoadEvent } from '@sveltejs/kit'; export const load = async ({ fetch, params }: LoadEvent) => { const network = getNetworkFromParams(String(params.network)); - const account = await AccountState.for(network, String(params.name), fetch); + let account: AccountState; + try { + account = await AccountState.for(network, String(params.name), fetch); + } catch (e) { + console.error(e); + error(404, { message: `Account not found: ${String(params.name)}`, code: 'NOT_FOUND' }); + } return { account, name: params.name diff --git a/src/routes/[network]/+error.svelte b/src/routes/[network]/+error.svelte new file mode 100644 index 000000000..931e28a82 --- /dev/null +++ b/src/routes/[network]/+error.svelte @@ -0,0 +1,12 @@ + + + + + +{#if $page.error?.code === 'NOT_FOUND'} +
{JSON.stringify($page.error, null, 2)}+{/if}