From 5bb3106dc7adae61cc5d4d5b0376c92b4a2cbbb3 Mon Sep 17 00:00:00 2001 From: g-tejas Date: Wed, 26 Jun 2024 13:01:24 +0800 Subject: [PATCH] feat(errors): revamp business logic error codes --- src/app/modules/core/core.errors.ts | 4 +++- src/app/modules/form/form.errors.ts | 2 +- .../email-submission/email-submission.controller.ts | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/modules/core/core.errors.ts b/src/app/modules/core/core.errors.ts index 995fe73015..dce8fa7739 100644 --- a/src/app/modules/core/core.errors.ts +++ b/src/app/modules/core/core.errors.ts @@ -7,8 +7,9 @@ export class ApplicationError extends Error { * Meta object to be logged by the application logger, if any. */ meta?: unknown + errorCode?: number - constructor(message?: string, meta?: unknown) { + constructor(message?: string, meta?: unknown, errorCode?: number) { super() Error.captureStackTrace(this, this.constructor) @@ -18,6 +19,7 @@ export class ApplicationError extends Error { this.message = message || 'Something went wrong. Please try again.' this.meta = meta + this.errorCode = errorCode } } diff --git a/src/app/modules/form/form.errors.ts b/src/app/modules/form/form.errors.ts index 5ef8cdc8cc..2bc8fec5a1 100644 --- a/src/app/modules/form/form.errors.ts +++ b/src/app/modules/form/form.errors.ts @@ -29,7 +29,7 @@ export class PrivateFormError extends ApplicationError { message = 'If you think this is a mistake, please contact the agency that gave you the form link.', formTitle: string, ) { - super(message) + super(message, 1001) this.formTitle = formTitle } } diff --git a/src/app/modules/submission/email-submission/email-submission.controller.ts b/src/app/modules/submission/email-submission/email-submission.controller.ts index 2cc6f73dde..375c89fab2 100644 --- a/src/app/modules/submission/email-submission/email-submission.controller.ts +++ b/src/app/modules/submission/email-submission/email-submission.controller.ts @@ -1,3 +1,4 @@ +import tracer from 'dd-trace' import { ok, okAsync, ResultAsync } from 'neverthrow' import { @@ -440,6 +441,11 @@ const submitEmailModeForm: ControllerHandler< }, ) .mapErr((error) => { + if (error?.errorCode) { + tracer.dogstatsd.increment('errorsV2', 1, { + error_code: error.errorCode, + }) + } const { errorMessage, statusCode } = mapRouteError(error) return res .status(statusCode)