fix: don't error out if API is not running during frontend build

This commit is contained in:
Sam 2023-05-24 16:17:30 +02:00
parent b7e0286cc7
commit 8f8daaa331
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
1 changed files with 20 additions and 3 deletions

View File

@ -1,6 +1,5 @@
import { error } from "@sveltejs/kit"; import { building } from "$app/environment";
import type { LayoutServerLoad } from "./$types"; import type { LayoutServerLoad } from "./$types";
import type { APIError } from "$lib/api/entities";
import { apiFetch } from "$lib/api/fetch"; import { apiFetch } from "$lib/api/fetch";
import type { MetaResponse } from "$lib/api/responses"; import type { MetaResponse } from "$lib/api/responses";
@ -8,6 +7,24 @@ export const load = (async () => {
try { try {
return await apiFetch<MetaResponse>("/meta", {}); return await apiFetch<MetaResponse>("/meta", {});
} catch (e) { } 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; }) satisfies LayoutServerLoad;