Skip to content

Commit

Permalink
#OBS-I285: fix: Logging errors in the middleware (#263)
Browse files Browse the repository at this point in the history
* #OBS-I285: fix: Logging errors in the middleware

* #OBS-I285: fix: Logging errors by excluding sensitive info

* #OBS-I285: fix: linting issue fix
  • Loading branch information
JeraldJF authored Oct 25, 2024
1 parent 33c8310 commit c90606f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api-service/src/helpers/ResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { onFailure, onObsrvFailure, onSuccess } from "../metrics/prometheus/help
import moment from "moment";
import _ from "lodash";
import { ObsrvError } from "../types/ObsrvError";
import logger from "../logger";

const ResponseHandler = {
successResponse: (req: Request, res: Response, result: Result) => {
Expand All @@ -26,6 +27,8 @@ const ResponseHandler = {

errorResponse: (error: Record<string, any>, req: Request, res: Response) => {
const { statusCode, message, errCode, code = "INTERNAL_SERVER_ERROR", trace = "" } = error;
const sanitizedError = { ...error, proxyAuthKey: "REDACTED" };
logger.error(sanitizedError)
const { id, entity, body } = req as any;
const msgid = _.get(body, ["params", "msgid"])
const resmsgid = _.get(res, "resmsgid")
Expand All @@ -37,6 +40,8 @@ const ResponseHandler = {

obsrvErrorResponse: (error: ObsrvError, req: Request, res: Response) => {
const { statusCode, message, errCode, code = "INTERNAL_SERVER_ERROR", data } = error;
const sanitizedError = { ...error, proxyAuthKey: "REDACTED" };
logger.error(sanitizedError)
const { id, entity, body } = req as any;
const msgid = _.get(body, ["params", "msgid"])
const resmsgid = _.get(res, "resmsgid")
Expand Down

0 comments on commit c90606f

Please sign in to comment.