misc: Improve error handling
This commit is contained in:
1 parent
98b5e4b5c1
commit
a5460a03b4
23 files changed
+285
-202
No files matched your search
+4
-2
@@ -1,4 +1,4 @@
|
||||
import { instance_url } from '$lib/lemmy.js'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/lemmy.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
export async function handle({ event, resolve }) {
|
||||
@@ -14,16 +14,18 @@ export async function handle({ event, resolve }) {
|
||||
event.request.headers.delete('host')
|
||||
|
||||
try {
|
||||
console.log(`https://${instance}/${url.toString()}`)
|
||||
const data = await fetch(`https://${instance}/${url.toString()}`, {
|
||||
method: event.request.method,
|
||||
body: event.request.body,
|
||||
headers: event.request.headers,
|
||||
signal: AbortSignal.timeout(20 * 1000),
|
||||
})
|
||||
|
||||
return new Response(JSON.stringify(await data.json()))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw error(500, `The proxy failed to fetch from ${instance}.`)
|
||||
throw error(500, { message: 'The proxy failed to fetch from the server' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user