Skip to content

Commit

Permalink
feat: improve setting error name
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Tkacz committed Aug 21, 2024
1 parent cada3d4 commit 6b10ffb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/errors/InternalError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('InternalError', () => {
message: 'Unknown',
errorCode: 'INTERNAL_ERROR',
})
this.name = 'ExtendedInternalError'
}
}
const err = new ExtendedInternalError()
Expand Down
3 changes: 2 additions & 1 deletion src/errors/InternalError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class InternalError<T = ErrorDetails> extends Error {
super(params.message, {
cause: params.cause,
})
this.name = 'InternalError'
// set the name as the class name for every class that extends InternalError
this.name = this.constructor.name
this.details = params.details
this.errorCode = params.errorCode
}
Expand Down
1 change: 0 additions & 1 deletion src/errors/PublicNonRecoverableError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('PublicNonRecoverableError', () => {
message: 'Unknown',
errorCode: 'PUBLIC_ERROR',
})
this.name = 'ExtendedPublicNonRecoverableError'
}
}
const err = new ExtendedPublicNonRecoverableError()
Expand Down
3 changes: 2 additions & 1 deletion src/errors/PublicNonRecoverableError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class PublicNonRecoverableError<T = ErrorDetails> extends Error {
super(params.message, {
cause: params.cause,
})
this.name = 'PublicNonRecoverableError'
// set the name as the class name for every class that extends PublicNonRecoverableError
this.name = this.constructor.name
this.details = params.details
this.errorCode = params.errorCode
this.httpStatusCode = params.httpStatusCode ?? 500
Expand Down

0 comments on commit 6b10ffb

Please sign in to comment.