Created
September 5, 2022 05:55
-
-
Save GautamPanickar/d65835cbd5e2bee3e487d5fc47d07688 to your computer and use it in GitHub Desktop.
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
import { Request, Response, NextFunction } from 'express'; | |
import HttpException from '../../utils/exceptions/base/httpexception'; | |
function errorMiddleware(error: HttpException, request: Request, response: Response, next: NextFunction) { | |
const status = error.status || 500; | |
const message = error.message || 'Something went wrong'; | |
const result = error.result || false; | |
console.log(`${request.method} | ${request.path} >> ${message}`); | |
response | |
.status(status) | |
.send({ | |
result, | |
message, | |
status, | |
}); | |
} | |
export default errorMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment