return json errors from valhalla api route

This commit is contained in:
Christian Beutel
2025-07-04 10:16:11 +02:00
parent fff3bd1bf7
commit 819aea801e

View File

@@ -5,16 +5,17 @@ import { error, json, type NumericRange, type RequestEvent } from "@sveltejs/kit
export async function POST(event: RequestEvent) { export async function POST(event: RequestEvent) {
const data = await event.request.json() const data = await event.request.json()
if (!env.PUBLIC_VALHALLA_URL) { if (!env.PUBLIC_VALHALLA_URL) {
return error(400, "PUBLIC_VALHALLA_URL not set") return json({ message: "PUBLIC_VALHALLA_URL not set" }, { status: 400 })
} }
try { try {
const r = await event.fetch(env.PUBLIC_VALHALLA_URL + '/route', { method: "POST", body: JSON.stringify(data) }); const r = await event.fetch(env.PUBLIC_VALHALLA_URL + '/route', { method: "POST", body: JSON.stringify(data) });
const response = await r.json(); const response = await r.json();
if (!r.ok) { if (!r.ok) {
throw error(r.status as NumericRange<400,500>, response); return json({ message: response }, { status: r.status })
} }
return json(response); return json(response);
} catch (e: any) { } catch (e: any) {
throw error(e.status || 500, e) return json({ message: e }, { status: 500 })
} }
} }