@geniucode/common-utils
Version:
Common utils
29 lines • 922 B
JavaScript
import * as ErrorList from '../errors/index';
export const errorHandler = (err, req, res, next) => {
let statusCode = null;
const msg = err?.message;
const defaultStatusCode = 500; // General Error Status Code when the type of error is Unknown
if (err instanceof ErrorList.RequestValidationErrorAsArray) {
const stack = err?.stack;
statusCode = err?.getStatusCode();
err = err.serializeErrors();
err.stack = stack;
}
else if (err instanceof ErrorList.CustomError) {
statusCode = err?.getStatusCode();
}
else {
}
statusCode = statusCode || defaultStatusCode;
res.status(statusCode).send({
status: false,
devCode: null,
statusCode,
msg,
errors: err,
stack: err?.stack,
});
};
// process.on('uncaughtException')
// process.on('unhandledRejection')
//# sourceMappingURL=error-handler.js.map