Skip to content

Commit 64b3013

Browse files
committed
favicon error handled inside global-error-handler
1 parent a2a9c58 commit 64b3013

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/global-error-handler.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ export function setErrorOptions(options: Partial<ErrorOptions>) {
3333
}
3434

3535

36+
37+
38+
3639
export const globalErrorHandler = (
3740
err: unknown,
3841
_req: Request,
3942
res: Response,
4043
_next: NextFunction
4144
) => {
45+
// 🚫 Ignoring harmless favicon.ico errors
46+
if (_req.originalUrl === '/favicon.ico') {
47+
return res.status(204).end();
48+
}
49+
4250
let statusCode: number = StatusCodes.INTERNAL_SERVER_ERROR;
4351
let message: string = getStatusMessage(StatusCodes.INTERNAL_SERVER_ERROR);
4452
let errorDetails: string | object | null | undefined;
@@ -70,27 +78,26 @@ export const globalErrorHandler = (
7078
errorResponse.stack = stack.split('\n').map((line) => line.trim());
7179
}
7280

73-
// Log the error if configured to do so
81+
// Logging the error if configured to do so
7482
if (errorOptions.logError) {
75-
7683
// log the intro line if it's true
77-
if (errorOptions.introLine) {
78-
console.error(`\n${(bold(`${errorOptions.introLine}`))}\n`);
84+
if (errorOptions.introLine) {
85+
console.error(`\n${bold(`${errorOptions.introLine}`)}\n`);
7986
} else {
8087
console.error();
8188
}
8289

83-
// log the error status
90+
// logging the error status
8491
console.error(
8592
`${boldRed('🔴 Error Status:')} ${red(String(errorResponse.status))}\n`
8693
);
8794

88-
// log the error message
95+
// logging the error message
8996
console.error(
9097
`${boldRed('🔴 Error Message:')} ${red(errorResponse.message)}\n`
9198
);
9299

93-
// Log error details if available
100+
// Logging error details if available
94101
if (errorResponse.errorDetails) {
95102
console.error(boldYellow('🟡 Error Details:'));
96103
console.error(
@@ -103,7 +110,7 @@ export const globalErrorHandler = (
103110
console.error();
104111
}
105112

106-
// Log stack trace if available
113+
// Logging stack trace if available
107114
if (errorResponse.stack) {
108115
const stackLines = errorResponse.stack as string[];
109116
const previewLines = stackLines.slice(0, 3);

0 commit comments

Comments
 (0)