-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix instaceof comparison for UnauthorizedError. closes #292
- Loading branch information
1 parent
b1344fa
commit 6c87fe4
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ export class UnauthorizedError extends Error { | |
|
||
constructor(code: ErrorCode, error: ErrorLike) { | ||
super(error.message); | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jfromaniello
Author
Member
|
||
this.code = code; | ||
this.status = 401; | ||
this.name = 'UnauthorizedError'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
|
@jfromaniello do you know why it fails without that line?
never saw such behavior
try to test same UnauthorizedError class, works without Object.setPrototypeOf
index.js