From 1234fdb8a1e8abf845e83c6d554fe5e0b587ec79 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Wed, 20 May 2026 01:00:17 +0100 Subject: [PATCH] feat: add centralized error handling in hooks.server.ts for improved error logging and debugging --- apps/dashboard/src/hooks.server.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/src/hooks.server.ts b/apps/dashboard/src/hooks.server.ts index 7e505fcc..659aeb9a 100644 --- a/apps/dashboard/src/hooks.server.ts +++ b/apps/dashboard/src/hooks.server.ts @@ -1,10 +1,23 @@ import { getSessionData } from '$lib/utils/services/auth/session'; import { getHasCioCookies } from '$lib/utils/functions/cookies'; import { applyCspExtensions } from '$lib/utils/csp'; -import { type Handle, redirect } from '@sveltejs/kit'; +import { type Handle, type HandleServerError, redirect } from '@sveltejs/kit'; import { isPublicApiRoute, isPublicRoute } from '$lib/utils/functions/routes/isPublicRoute'; import { ROUTE } from '$lib/utils/constants/routes'; +export const handleError: HandleServerError = ({ error, event, status, message }) => { + const err = error as Error; + console.error('[handleError]', { + status, + message, + method: event.request.method, + url: event.url.toString(), + name: err?.name, + msg: err?.message, + stack: err?.stack + }); +}; + const ANALYTICS_SESSION_COOKIE = 'cio_aid'; const ANALYTICS_SESSION_MAX_AGE = 60 * 60 * 24 * 90;