fix: Fix error handling (i hope)
This commit is contained in:
1 parent
3b33a9d194
commit
87817aaa34
3 files changed
+14
-5
No files matched your search
+12
-4
@@ -30,7 +30,7 @@ export async function handle({ event, resolve }) {
|
||||
})
|
||||
|
||||
if (!data.ok) {
|
||||
console.log(`${data.status}: ${data.statusText}`)
|
||||
await resolve(event)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: await data.text(),
|
||||
@@ -44,10 +44,17 @@ export async function handle({ event, resolve }) {
|
||||
try {
|
||||
const json = await data.json()
|
||||
|
||||
return new Response(JSON.stringify(json), {
|
||||
status: data.status,
|
||||
})
|
||||
await resolve(event)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: 'Failed to fetch',
|
||||
}),
|
||||
{
|
||||
status: data.status,
|
||||
}
|
||||
)
|
||||
} catch (err) {
|
||||
await resolve(event)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: 'Failed to fetch',
|
||||
@@ -58,6 +65,7 @@ export async function handle({ event, resolve }) {
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
await resolve(event)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: 'the proxy failed to fetch from server',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import { addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
/>
|
||||
{:catch}
|
||||
<div class="bg-red-500/10 border border-red-500 rounded-md p-4">
|
||||
Failed to load posts
|
||||
Failed to load comments.
|
||||
</div>
|
||||
{/await}
|
||||
</div>
|
||||
Reference in new issue
Block a user