-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from trojs/feature/access-error
Add the Access error
- Loading branch information
Showing
8 changed files
with
84 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,49 @@ | ||
import { describe, it } from 'node:test' | ||
import assert from 'node:assert' | ||
import { AccessError } from '../index.js' | ||
|
||
/* eslint-disable sonarjs/no-duplicate-string */ | ||
|
||
describe('Access Error test', () => { | ||
it('It should create an Access error', () => { | ||
const error = new AccessError({ | ||
value: 'test', | ||
type: String, | ||
message: 'Example text' | ||
}) | ||
|
||
assert.deepEqual(error instanceof AccessError, true) | ||
assert.deepEqual(error instanceof TypeError, true) | ||
assert.deepEqual(error instanceof Error, true) | ||
assert.deepEqual(error.name, 'AccessError') | ||
assert.deepEqual(error.message, 'Example text') | ||
assert.deepEqual(error.value, 'test') | ||
assert.deepEqual(error.status, 403) | ||
assert.deepEqual(error.type, String) | ||
assert.deepEqual(error.date.constructor, Date) | ||
assert.deepEqual( error.stack.includes('AccessError: Example text') , true) | ||
}) | ||
|
||
it('It should handle invalid error values', () => { | ||
const error = new AccessError({ | ||
value: 'test', | ||
type: 'string', | ||
message: 'Example text' | ||
}) | ||
|
||
assert.deepEqual(error instanceof AccessError, true) | ||
assert.deepEqual(error instanceof Error, true) | ||
assert.deepEqual(error.name, 'AccessError') | ||
assert.deepEqual(error.message, 'Invalid error') | ||
assert.deepEqual(error.value.errors[0][0], 'type?') | ||
assert.deepEqual(error.value.values.message, 'Invalid error') | ||
assert.deepEqual(error.value.values.name, 'AccessError') | ||
assert.deepEqual(error.value.values.status, 403) | ||
assert.deepEqual(error.value.values.type, Error) | ||
assert.deepEqual(error.value.values.value, 'test') | ||
assert.deepEqual(error.status, 500) | ||
assert.deepEqual(error.type, Error) | ||
assert.deepEqual(error.date.constructor, Date) | ||
assert.deepEqual( error.stack.includes('AccessError: Invalid error') , true) | ||
}) | ||
}) |
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
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,23 @@ | ||
import makeAppError from './app-error.js' | ||
|
||
const AppError = makeAppError(TypeError) | ||
|
||
class AccessError extends AppError { | ||
/** | ||
* Get the error name | ||
* @returns {string} | ||
*/ | ||
get name() { | ||
return 'AccessError' | ||
} | ||
|
||
/** | ||
* Get the error status | ||
* @returns {number} | ||
*/ | ||
get errorStatus() { | ||
return 403 | ||
} | ||
} | ||
|
||
export default AccessError |
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