+
+ Oops! Something went wrong
+ +
+
+ Go Home
+
+ diff --git a/src/components/ErrorBoundary.svelte b/src/components/ErrorBoundary.svelte new file mode 100644 index 0000000..f73bbed --- /dev/null +++ b/src/components/ErrorBoundary.svelte @@ -0,0 +1,167 @@ + + +
{message}
+ + {#if details} + + + {#if showDetails} +{JSON.stringify(details, null, 2)}
+ {error}
+Browse all companies. Total: {totalRecords} companies
{/if} diff --git a/src/routes/company/[id]/+page.server.ts b/src/routes/company/[id]/+page.server.ts new file mode 100644 index 0000000..8498ae8 --- /dev/null +++ b/src/routes/company/[id]/+page.server.ts @@ -0,0 +1,35 @@ +import { company } from "$lib/companies"; +import type { PageServerLoad } from "./$types"; +import { error } from "@sveltejs/kit"; + +export const load: PageServerLoad = async ({ params, parent }) => { + const { session } = await parent(); + + if (!session.accessToken) { + throw error(401, "Unauthorized: Access token required"); + } + + try { + const companyData = await company.fetch(session.accessToken, params.id); + + if (!companyData) { + throw error(404, `Company with ID ${params.id} not found`); + } + + return { + company: companyData, + }; + } catch (err) { + console.error("Failed to fetch company:", err); + + if (err instanceof Error && err.message.includes("404")) { + throw error(404, `Company with ID ${params.id} not found`); + } + + if (err instanceof Error && err.message.includes("401")) { + throw error(401, "Your session has expired. Please log in again."); + } + + throw error(500, "Failed to load company details. Please try again."); + } +}; diff --git a/src/routes/company/[id]/+page.svelte b/src/routes/company/[id]/+page.svelte new file mode 100644 index 0000000..3152d20 --- /dev/null +++ b/src/routes/company/[id]/+page.svelte @@ -0,0 +1,119 @@ + + +{JSON.stringify(data.company, null, 2)}
+