Skip to content

Commit

Permalink
fix: condition for exposing error via middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Oct 7, 2024
1 parent 4b4fae4 commit e7a5fee
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/server-http-kit/src/middlewares/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.';
}

Expand All @@ -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 : {}),
};
}));
}

0 comments on commit e7a5fee

Please sign in to comment.