Skip to content

Commit

Permalink
Fix issue where error reporting wrong instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Nov 18, 2021
1 parent 3060c89 commit 1954087
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@
}
},
"preset": "ts-jest",
"globals": {
"ts-jest": {
"tsconfig": {
"target": "es6"
}
}
},
"globalSetup": "./tests/global-setup.ts",
"setupFilesAfterEnv": [
"./tests/setup.ts"
Expand Down
4 changes: 4 additions & 0 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HttpError } from 'http-errors';
export class AccessTokenError extends Error {
public code: string;

/* istanbul ignore next */
constructor(code: string, message: string) {
super(message);

Expand All @@ -19,6 +20,7 @@ export class AccessTokenError extends Error {

// Machine readable code.
this.code = code;
Object.setPrototypeOf(this, AccessTokenError.prototype);
}
}

Expand Down Expand Up @@ -48,6 +50,7 @@ export class HandlerError extends Error {
public status: number | undefined;
public code: string | undefined;

/* istanbul ignore next */
constructor(error: Error | AccessTokenError | HttpError) {
super(htmlSafe(error.message));

Expand All @@ -60,5 +63,6 @@ export class HandlerError extends Error {
if ('status' in error) {
this.status = error.status;
}
Object.setPrototypeOf(this, HandlerError.prototype);
}
}
8 changes: 8 additions & 0 deletions tests/utils/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AccessTokenError, HandlerError } from '../../src/utils/errors';

describe('errors', () => {
test('should be instance of themselves', () => {
expect(new AccessTokenError('code', 'message')).toBeInstanceOf(AccessTokenError);
expect(new HandlerError(new Error('message'))).toBeInstanceOf(HandlerError);
});
});

0 comments on commit 1954087

Please sign in to comment.