From e7a5feec09eec7f63c91e13781b4abc19cb787f6 Mon Sep 17 00:00:00 2001 From: tada5hi Date: Mon, 7 Oct 2024 17:56:18 +0200 Subject: [PATCH] fix: condition for exposing error via middleware --- packages/server-http-kit/src/middlewares/error.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/server-http-kit/src/middlewares/error.ts b/packages/server-http-kit/src/middlewares/error.ts index b6fb3e67f..3b9e35d2b 100644 --- a/packages/server-http-kit/src/middlewares/error.ts +++ b/packages/server-http-kit/src/middlewares/error.ts @@ -17,7 +17,7 @@ export function mountErrorMiddleware(router: Router) { const isServerError = error.statusCode >= 500 && error.statusCode < 600; - if (isServerError) { + if (isServerError || error.logMessage) { useLogger().error(error); if (error.cause) { @@ -62,7 +62,8 @@ export function mountErrorMiddleware(router: Router) { const exposeError = typeof error.expose === 'boolean' ? error.expose : !isServerError; - if (exposeError) { + + if (!exposeError) { error.message = 'An internal server error occurred.'; } @@ -72,7 +73,7 @@ export function mountErrorMiddleware(router: Router) { statusCode: error.statusCode, code: `${error.code}`, message: error.message, - ...(isObject(error.data) && exposeError ? error.data : {}), + ...(exposeError && isObject(error.data) ? error.data : {}), }; })); }