Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing array of codes to
isHttpErrorCode
- Loading branch information
1 parent
7448b5c
commit 961f32f
Showing
4 changed files
with
80 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@farfetched/core': minor | ||
--- | ||
|
||
Allow passing array of codes to `isHttpErrorCode` |
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
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,50 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import { httpError } from '../create_error'; | ||
|
||
import { isHttpErrorCode } from '../guards'; | ||
|
||
describe('isHttpErrorCode', () => { | ||
test('isHttpErrorCode supports array of codes', () => { | ||
const check401or403 = isHttpErrorCode([401, 403]); | ||
|
||
expect( | ||
check401or403({ | ||
error: httpError({ | ||
status: 401, | ||
statusText: 'Text', | ||
response: {}, | ||
}), | ||
}) | ||
).toBe(true); | ||
|
||
expect( | ||
check401or403({ | ||
error: httpError({ | ||
status: 403, | ||
statusText: 'Text', | ||
response: {}, | ||
}), | ||
}) | ||
).toBe(true); | ||
|
||
expect( | ||
check401or403({ | ||
error: httpError({ | ||
status: 400, | ||
statusText: 'Text', | ||
response: {}, | ||
}), | ||
}) | ||
).toBe(false); | ||
|
||
expect( | ||
check401or403({ | ||
error: httpError({ | ||
status: 404, | ||
statusText: 'Text', | ||
response: {}, | ||
}), | ||
}) | ||
).toBe(false); | ||
}); | ||
}); |
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