diff --git a/src/errors/UnauthorizedError.ts b/src/errors/UnauthorizedError.ts index 64550e5a..f4f0bc96 100644 --- a/src/errors/UnauthorizedError.ts +++ b/src/errors/UnauthorizedError.ts @@ -13,6 +13,7 @@ export class UnauthorizedError extends Error { constructor(code: ErrorCode, error: ErrorLike) { super(error.message); + Object.setPrototypeOf(this, UnauthorizedError.prototype); this.code = code; this.status = 401; this.name = 'UnauthorizedError'; diff --git a/test/UnauthorizedError.test.ts b/test/UnauthorizedError.test.ts new file mode 100644 index 00000000..d6952131 --- /dev/null +++ b/test/UnauthorizedError.test.ts @@ -0,0 +1,19 @@ +import { UnauthorizedError } from '../src/errors/UnauthorizedError'; +import assert from 'assert'; + +describe('Unauthorized Error', () => { + const e = new UnauthorizedError('credentials_bad_format', new Error('a')); + + it('should be an instance of UnauthorizedError', () => { + assert.ok(e instanceof UnauthorizedError); + }); + + it('should contains the error code', () => { + assert.ok(e.code, 'credentials_bad_format'); + }); + + it('should contains the error message', () => { + assert.ok(e.code, 'a'); + }); +}); +