-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
618f648
commit 6635ff7
Showing
8 changed files
with
707 additions
and
125 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { Request, Response } from 'express'; | ||
|
||
type MiddlewareFunction = (req: Request, res: Response, next: NextFunction) => Promise<void>; | ||
type MiddlewareFunction = (req: Request, res: Response) => Promise<Response<Record<string, unknown>> | undefined>; | ||
|
||
function errorHandler(func: MiddlewareFunction) { | ||
return async (req: Request, res: Response, next: NextFunction) => { | ||
function errorHandler(func: MiddlewareFunction): MiddlewareFunction { | ||
return async (req: Request, res: Response) => { | ||
try { | ||
await func(req, res, next); | ||
} catch (error) { // Removed the type annotation from the catch clause variable because it caused liting errors | ||
const message = error.detail || 'Internal Server Error'; | ||
res.status(500).send(message); | ||
return await func(req, res); | ||
} catch (error) { | ||
const message = (error as { detail?: string }).detail || 'Internal Server Error'; | ||
return res.status(500).send(message); | ||
} | ||
}; | ||
} | ||
|
||
export default errorHandler; | ||
export default errorHandler; |