-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize error handler and response message
- Loading branch information
1 parent
80c9aae
commit 6c2957a
Showing
8 changed files
with
59 additions
and
69 deletions.
There are no files selected for viewing
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,6 +1,13 @@ | ||
import { ErrorRequestHandler } from 'express'; | ||
import { CustomResponseType } from '../types/customResponseType'; | ||
export const DefaultException: ErrorRequestHandler = (err, req, res) => { | ||
err.status = CustomResponseType.SYSTEM_ERROR; | ||
res.status(500).json(err); | ||
import log4js from '../config/log4js'; | ||
const logger = log4js.getLogger(`DefaultException`); | ||
|
||
export const DefaultException: ErrorRequestHandler = (err, req, res, next) => { | ||
logger.error(err); | ||
err.statusCode = err.statusCode || 500; | ||
return res.status(err.statusCode).json({ | ||
status: err.status, | ||
message: err.message, | ||
data: err.data, | ||
}); | ||
}; |
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