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 5bb3106
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 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) {
super()

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

this.meta = meta
this.errorCode = errorCode
}
}

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,3 +1,4 @@
import tracer from 'dd-trace'
import { ok, okAsync, ResultAsync } from 'neverthrow'

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

0 comments on commit 5bb3106

Please sign in to comment.