fix: Fix error handling (i hope)

This commit is contained in:
Xyphyn committed 2023-07-04 14:26:39 -07:00
1 parent 3b33a9d194
commit 87817aaa34
3 files changed
+14 -5

No files matched your search

+12 -4
View File
@@ -30,7 +30,7 @@ export async function handle({ event, resolve }) {
}) })
if (!data.ok) { if (!data.ok) {
console.log(`${data.status}: ${data.statusText}`) await resolve(event)
return new Response( return new Response(
JSON.stringify({ JSON.stringify({
message: await data.text(), message: await data.text(),
@@ -44,10 +44,17 @@ export async function handle({ event, resolve }) {
try { try {
const json = await data.json() const json = await data.json()
return new Response(JSON.stringify(json), { await resolve(event)
status: data.status, return new Response(
}) JSON.stringify({
message: 'Failed to fetch',
}),
{
status: data.status,
}
)
} catch (err) { } catch (err) {
await resolve(event)
return new Response( return new Response(
JSON.stringify({ JSON.stringify({
message: 'Failed to fetch', message: 'Failed to fetch',
@@ -58,6 +65,7 @@ export async function handle({ event, resolve }) {
) )
} }
} catch (error) { } catch (error) {
await resolve(event)
return new Response( return new Response(
JSON.stringify({ JSON.stringify({
message: 'the proxy failed to fetch from server', message: 'the proxy failed to fetch from server',
+1
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores' import { page } from '$app/stores'
import Link from '$lib/components/input/Link.svelte' import Link from '$lib/components/input/Link.svelte'
import { addToast } from '$lib/components/ui/toasts/toasts.js'
</script> </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">
+1 -1
View File
@@ -156,7 +156,7 @@
/> />
{:catch} {:catch}
<div class="bg-red-500/10 border border-red-500 rounded-md p-4"> <div class="bg-red-500/10 border border-red-500 rounded-md p-4">
Failed to load posts Failed to load comments.
</div> </div>
{/await} {/await}
</div> </div>