Skip to content

Instantly share code, notes, and snippets.

@GautamPanickar
Created September 5, 2022 05:55
Show Gist options
  • Save GautamPanickar/d65835cbd5e2bee3e487d5fc47d07688 to your computer and use it in GitHub Desktop.
Save GautamPanickar/d65835cbd5e2bee3e487d5fc47d07688 to your computer and use it in GitHub Desktop.
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