* server sided external api calls * fix uploading gpx files * rename api/v1/nominatim with api/v1/geocoding to prepare photon support * remove NOMINATIM_MAX_RETRIES (side-kick from other PR) * re-add nominatim url fallback * docu, env var defaults and fallbacks, docker compose files * refactor * furhter refactorings and fixes * PUBLIC_VALHALLA_ENABLED in docker compose files added * fix env var names --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com>
19 lines
452 B
TypeScript
19 lines
452 B
TypeScript
import { json } from "@sveltejs/kit";
|
|
|
|
function safeJson(text: string): any {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch {
|
|
return { message: text };
|
|
}
|
|
}
|
|
|
|
export async function proxyJsonResponse(response: Response) {
|
|
const text = await response.text();
|
|
const payload = text.length ? safeJson(text) : {};
|
|
if (!response.ok) {
|
|
return json(payload, { status: response.status });
|
|
}
|
|
return json(payload);
|
|
}
|