From 8f8daaa331eb68fa97b07afccc42df4ef56d23c8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 May 2023 16:17:30 +0200 Subject: [PATCH] fix: don't error out if API is not running during frontend build --- frontend/src/routes/+layout.server.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/+layout.server.ts b/frontend/src/routes/+layout.server.ts index d26a80c..1af3ac9 100644 --- a/frontend/src/routes/+layout.server.ts +++ b/frontend/src/routes/+layout.server.ts @@ -1,6 +1,5 @@ -import { error } from "@sveltejs/kit"; +import { building } from "$app/environment"; import type { LayoutServerLoad } from "./$types"; -import type { APIError } from "$lib/api/entities"; import { apiFetch } from "$lib/api/fetch"; import type { MetaResponse } from "$lib/api/responses"; @@ -8,6 +7,24 @@ export const load = (async () => { try { return await apiFetch("/meta", {}); } catch (e) { - throw error(500, (e as APIError).message); + console.warn("error fetching meta endpoint:", e); + + if (building) { + // just return an empty object--this only affects the three static pages, nothing else, so it's fine + return { + git_repository: "", + git_commit: "", + users: { + total: 0, + active_month: 0, + active_week: 0, + active_day: 0, + }, + members: 0, + require_invite: false, + }; + } else { + throw e; + } } }) satisfies LayoutServerLoad;