feat: improve error handling
This commit is contained in:
1 parent
4b6878ffac
commit
e34cace14f
8 files changed
+39
-31
No files matched your search
@@ -0,0 +1,5 @@
|
||||
export function handleError({ error, event }) {
|
||||
return {
|
||||
message: error as any,
|
||||
}
|
||||
}
|
||||
@@ -49,24 +49,25 @@
|
||||
{/if}
|
||||
<p class="text-sm">{toast.content}</p>
|
||||
</div>
|
||||
<div class="ml-auto" />
|
||||
{#if toast.action}
|
||||
<div class="ml-auto flex items-center gap-2 m-2">
|
||||
{#if toast.action}
|
||||
<button
|
||||
on:click={() => {
|
||||
toast.action?.()
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2"
|
||||
>
|
||||
<Icon src={Check} size="16" mini />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
on:click={() => {
|
||||
toast.action?.()
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2 m-2"
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2"
|
||||
>
|
||||
<Icon src={Check} size="16" mini />
|
||||
<Icon src={XMark} size="16" mini />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
on:click={() => {
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2 m-2"
|
||||
>
|
||||
<Icon src={XMark} size="16" mini />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
+13
-1
@@ -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<Response> {
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function match(param) {
|
||||
return /^\d+$/.test(param)
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center h-full">
|
||||
<h1 class="font-black text-5xl">{$page.status}</h1>
|
||||
<p>Failed to fetch that page. Is it missing?</p>
|
||||
<p>Failed to fetch that page.</p>
|
||||
<code>{$page.error?.message}</code>
|
||||
<Button href={$page.url.toString()}>Retry</Button>
|
||||
</div>
|
||||
@@ -1,14 +0,0 @@
|
||||
<script>
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||
<h1 class="font-black text-3xl">404</h1>
|
||||
<p class="mx-4 md:mx-8">
|
||||
It's likely that this community hasn't been federated (nobody on your
|
||||
instance has subscribed to it yet.)
|
||||
</p>
|
||||
<Button on:click={() => goto($page.url)}>Retry</Button>
|
||||
</div>
|
||||
File renamed without changes.
+1
@@ -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 }) {
|
||||
Reference in new issue
Block a user