print requestError logs in backend when in dev mode

This commit is contained in:
Maidul Islam
2023-01-04 15:32:45 -05:00
parent 68c488b8ee
commit fba40b5d4b
@@ -4,10 +4,17 @@ import * as Sentry from '@sentry/node';
import { InternalServerError } from "../utils/errors"; import { InternalServerError } from "../utils/errors";
import { getLogger } from "../utils/logger"; import { getLogger } from "../utils/logger";
import RequestError, { LogLevel } from "../utils/requestError"; import RequestError, { LogLevel } from "../utils/requestError";
import { NODE_ENV } from "../config";
export const requestErrorHandler: ErrorRequestHandler = (error: RequestError | Error, req, res, next) => { export const requestErrorHandler: ErrorRequestHandler = (error: RequestError | Error, req, res, next) => {
if (res.headersSent) return next(); if (res.headersSent) return next();
if (NODE_ENV !== "production" && error instanceof RequestError) {
/* eslint-disable no-console */
console.log(error)
/* eslint-enable no-console */
}
//TODO: Find better way to type check for error. In current setting you need to cast type to get the functions and variables from RequestError //TODO: Find better way to type check for error. In current setting you need to cast type to get the functions and variables from RequestError
if (!(error instanceof RequestError)) { if (!(error instanceof RequestError)) {
error = InternalServerError({ context: { exception: error.message }, stack: error.stack }) error = InternalServerError({ context: { exception: error.message }, stack: error.stack })