Skip to content

Commit

Permalink
feat(errors): revamp business logic error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
g-tejas committed Jun 26, 2024
1 parent 4ceb3d1 commit 5e4f1f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/app/modules/core/core.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 1000) {
super()

Error.captureStackTrace(this, this.constructor)
Expand All @@ -18,6 +19,20 @@ export class ApplicationError extends Error {
this.message = message || 'Something went wrong. Please try again.'

this.meta = meta
this.errorCode = errorCode
}

consume(consumer: (error: this) => void): ApplicationError {
consumer(this)
return this
}

toJson() {
return JSON.stringify(this)
}

toJsonPretty() {
return JSON.stringify(this, null, 2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/form/form.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import tracer from 'dd-trace'
import { ok, okAsync, ResultAsync } from 'neverthrow'

import { statsdClient } from 'src/app/config/datadog-statsd-client'

Check failure on line 4 in src/app/modules/submission/email-submission/email-submission.controller.ts

View workflow job for this annotation

GitHub Actions / backend_lint

'statsdClient' is defined but never used

Check failure on line 4 in src/app/modules/submission/email-submission/email-submission.controller.ts

View workflow job for this annotation

GitHub Actions / backend_lint

'statsdClient' is defined but never used

import {
FormAuthType,
SubmissionErrorDto,
Expand Down Expand Up @@ -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<
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5e4f1f9

Please sign in to comment.