Skip to content

Commit

Permalink
add context
Browse files Browse the repository at this point in the history
  • Loading branch information
david1542 committed Jul 25, 2024
1 parent 2e1b280 commit 7920b34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions services/api/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ export class AppError extends Error {
public readonly statusCode: number;
public readonly status: "fail" | "error";
public readonly internalCode?: ErrorCode;
constructor(payload: ErrorPayload) {
super(payload.message);
this.stack = payload.stack;
this.message = payload.message;
this.statusCode = payload.statusCode;
this.status = `${payload.statusCode}`.startsWith("4") ? "fail" : "error";
this.internalCode = payload.internalCode;
public readonly context: Record<string, unknown> | undefined;

constructor({
message,
statusCode,
internalCode,
stack,
context,
}: ErrorPayload) {
super(message);

this.stack = stack;
this.message = message;
this.statusCode = statusCode;
this.status = `${statusCode}`.startsWith("4") ? "fail" : "error";
this.internalCode = internalCode;
this.context = context;

Error.captureStackTrace(this, this.constructor);
}
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/middlewares/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const captureErrorInTelemetry = (error: AppError) => {
distinctId: uuid(),
properties: {
message: error.message,
context: error.context,
},
});
};
const productionError = (error: AppError, res: Response) => {

captureErrorInTelemetry(error);

// Send a lean error message
Expand Down

0 comments on commit 7920b34

Please sign in to comment.