-
-
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.
- Loading branch information
1 parent
2b65db3
commit 42dc540
Showing
6 changed files
with
89 additions
and
13 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 { ProcessingError } from '../index.js' | ||
|
||
/* eslint-disable sonarjs/no-duplicate-string */ | ||
|
||
describe('Processing Error test', () => { | ||
it('It should create a Processing error', () => { | ||
const error = new ProcessingError({ | ||
value: 'test', | ||
type: String, | ||
message: 'Example text' | ||
}) | ||
|
||
assert.deepEqual(error instanceof ProcessingError, true) | ||
assert.deepEqual(error instanceof TypeError, true) | ||
assert.deepEqual(error instanceof Error, true) | ||
assert.deepEqual(error.name, 'ProcessingError') | ||
assert.deepEqual(error.message, 'Example text') | ||
assert.deepEqual(error.value, 'test') | ||
assert.deepEqual(error.status, 422) | ||
assert.deepEqual(error.type, String) | ||
assert.deepEqual(error.date.constructor, Date) | ||
assert.deepEqual( error.stack.includes('ProcessingError: Example text') , true) | ||
}) | ||
|
||
it('It should handle invalid error values', () => { | ||
const error = new ProcessingError({ | ||
value: 'test', | ||
type: 'string', | ||
message: 'Example text' | ||
}) | ||
|
||
assert.deepEqual(error instanceof ProcessingError, true) | ||
assert.deepEqual(error instanceof Error, true) | ||
assert.deepEqual(error.name, 'ProcessingError') | ||
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, 'ProcessingError') | ||
assert.deepEqual(error.value.values.status, 422) | ||
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('ProcessingError: 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
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 ProcessingError extends AppError { | ||
/** | ||
* Get the error name | ||
* @returns {string} | ||
*/ | ||
get name() { | ||
return 'ProcessingError' | ||
} | ||
|
||
/** | ||
* Get the error status | ||
* @returns {number} | ||
*/ | ||
get errorStatus() { | ||
return 422 | ||
} | ||
} | ||
|
||
export default ProcessingError |