diff --git a/src/app/modules/core/core.errors.ts b/src/app/modules/core/core.errors.ts index 995fe73015..6b6ee352a0 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,20 @@ export class ApplicationError extends Error { this.message = message || 'Something went wrong. Please try again.' this.meta = meta + this.errorCode = errorCode || 1000 + } + + consume(consumer: (error: this) => void): ApplicationError { + consumer(this) + return this + } + + toJson() { + return JSON.stringify(this) + } + + toJsonPretty() { + return JSON.stringify(this, null, 2) } } 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..403fa781f8 100644 --- a/src/app/modules/submission/email-submission/email-submission.controller.ts +++ b/src/app/modules/submission/email-submission/email-submission.controller.ts @@ -1,5 +1,8 @@ +import tracer from 'dd-trace' import { ok, okAsync, ResultAsync } from 'neverthrow' +import { statsdClient } from 'src/app/config/datadog-statsd-client' + import { FormAuthType, SubmissionErrorDto, @@ -44,6 +47,10 @@ import * as EmailSubmissionService from './email-submission.service' import { IPopulatedEmailFormWithResponsesAndHash } from './email-submission.types' import { mapRouteError, SubmissionEmailObj } from './email-submission.util' +// export const errorStatsdClient = statsdClient.childClient({ +// prefix: 'errorsV2.email-submission.', +// }) + const logger = createLoggerWithLabel(module) const submitEmailModeForm: ControllerHandler< @@ -440,6 +447,15 @@ const submitEmailModeForm: ControllerHandler< }, ) .mapErr((error) => { + if (error.errorCode != 100) { + // tejastodo + tracer.dogstatsd.increment( + 'errorsV2.email-submission.submitEmailModeForm', + 1, + undefined, + ) + // errorStatsdClient.increment('submitEmailModeForm') + } const { errorMessage, statusCode } = mapRouteError(error) return res .status(statusCode)