diff options
| author | Ritesh Ghosh <[email protected]> | 2023-08-07 14:50:18 +0530 |
|---|---|---|
| committer | Ritesh Ghosh <[email protected]> | 2023-08-07 14:50:18 +0530 |
| commit | c543ab83fbbe2c45a9065f75a80dd347aec79292 (patch) | |
| tree | 2736a708f2789ed817f6cf4f4a7d3b32c881fef9 /src/config | |
| parent | 53af5cbc253b318e28898c4be77b2580eb88c7b9 (diff) | |
| download | aniwatch-api-c543ab83fbbe2c45a9065f75a80dd347aec79292.tar.xz aniwatch-api-c543ab83fbbe2c45a9065f75a80dd347aec79292.zip | |
refactor: added `errorHandler`
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/errorHandler.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/config/errorHandler.ts b/src/config/errorHandler.ts new file mode 100644 index 0000000..e983f34 --- /dev/null +++ b/src/config/errorHandler.ts @@ -0,0 +1,11 @@ +import { ErrorRequestHandler } from "express"; + +const errorHandler: ErrorRequestHandler = (error, req, res, next) => { + const status = error?.status || 500; + res.status(status).json({ + status, + message: error?.message || "Something Went Wrong", + }); +}; + +export default errorHandler; |
