Skip to content

Commit 2e26b95

Browse files
committed
Dashboard: Improve error reporting
1 parent 4b7c9e1 commit 2e26b95

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { HandleServerError } from '@sveltejs/kit'
2+
3+
export const handleError: HandleServerError = ({ error, event }) => {
4+
const hasAccess = event.request.headers.get('cf-access-authenticated-user-email')
5+
if (hasAccess) {
6+
const err = error instanceof Error ? `${error.message}\n${error.stack}` : String(error)
7+
return { message: err }
8+
}
9+
return { message: 'Internal Error' }
10+
}

apps/analytics-dashboard/src/routes/api/report/+server.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,17 @@ function formatReport(data: DashboardData): string {
337337
}
338338

339339
export const GET: RequestHandler = async ({ url, platform }) => {
340-
const data = await fetchDashboardData(platform, url.searchParams.get('range') ?? '7d')
341-
const report = formatReport(data)
342-
343-
return new Response(report, {
344-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
345-
})
340+
try {
341+
const data = await fetchDashboardData(platform, url.searchParams.get('range') ?? '7d')
342+
const report = formatReport(data)
343+
344+
return new Response(report, {
345+
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
346+
})
347+
} catch (e) {
348+
const err = e instanceof Error ? `${e.message}\n${e.stack}` : String(e)
349+
return new Response(`Report generation failed:\n${err}`, {
350+
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
351+
})
352+
}
346353
}

0 commit comments

Comments
 (0)