File tree Expand file tree Collapse file tree
apps/analytics-dashboard/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -337,10 +337,17 @@ function formatReport(data: DashboardData): string {
337337}
338338
339339export 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}
You can’t perform that action at this time.
0 commit comments