diff --git a/src/hooks.client.ts b/src/hooks.client.ts new file mode 100644 index 00000000..30ce35d1 --- /dev/null +++ b/src/hooks.client.ts @@ -0,0 +1,5 @@ +export function handleError({ error, event }) { + return { + message: error as any, + } +} diff --git a/src/lib/components/ui/toasts/Toast.svelte b/src/lib/components/ui/toasts/Toast.svelte index 2f7ce0e0..e7c4ca4c 100644 --- a/src/lib/components/ui/toasts/Toast.svelte +++ b/src/lib/components/ui/toasts/Toast.svelte @@ -49,24 +49,25 @@ {/if}

{toast.content}

-
- {#if toast.action} +
+ {#if toast.action} + + {/if} - {/if} - +
diff --git a/src/lib/lemmy.ts b/src/lib/lemmy.ts index 0db92ac6..6c6f82d4 100644 --- a/src/lib/lemmy.ts +++ b/src/lib/lemmy.ts @@ -7,17 +7,29 @@ import { import { get, writable } from 'svelte/store' import { env } from '$env/dynamic/public' import { profile } from '$lib/auth.js' +import { error } from '@sveltejs/kit' export const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml' export let instance = writable(DEFAULT_INSTANCE_URL) +async function customFetch( + input: RequestInfo | URL, + init?: RequestInit | undefined +): Promise { + const res = await fetch(input, init) + if (!res.ok) throw error(res.status, res.statusText) + return res +} + export function getClient(instanceURL?: string): LemmyHttp { if (!instanceURL) { instanceURL = get(instance) } - return new LemmyHttp(`https://${instanceURL}`) + return new LemmyHttp(`https://${instanceURL}`, { + fetchFunction: customFetch, + }) } export const getInstance = () => get(instance) diff --git a/src/params/integer.ts b/src/params/integer.ts new file mode 100644 index 00000000..f1e16d3c --- /dev/null +++ b/src/params/integer.ts @@ -0,0 +1,3 @@ +export function match(param) { + return /^\d+$/.test(param) +} diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte index 3d36dfc4..a79f8ff2 100644 --- a/src/routes/+error.svelte +++ b/src/routes/+error.svelte @@ -3,9 +3,9 @@ import Button from '$lib/components/input/Button.svelte' -
+

{$page.status}

-

Failed to fetch that page. Is it missing?

+

Failed to fetch that page.

{$page.error?.message}
diff --git a/src/routes/c/[name]/+error.svelte b/src/routes/c/[name]/+error.svelte deleted file mode 100644 index 460a55e8..00000000 --- a/src/routes/c/[name]/+error.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - -
-

404

-

- It's likely that this community hasn't been federated (nobody on your - instance has subscribed to it yet.) -

- -
diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte similarity index 100% rename from src/routes/post/[instance]/[id]/+page.svelte rename to src/routes/post/[instance]/[id=integer]/+page.svelte diff --git a/src/routes/post/[instance]/[id]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts similarity index 96% rename from src/routes/post/[instance]/[id]/+page.ts rename to src/routes/post/[instance]/[id=integer]/+page.ts index 37313ffc..7adde7de 100644 --- a/src/routes/post/[instance]/[id]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,5 +1,6 @@ import { profile } from '$lib/auth.js' import { getClient } from '$lib/lemmy.js' +import { error } from '@sveltejs/kit' import { get } from 'svelte/store' export async function load({ params, url }) {