Skip to content

Commit

Permalink
Merge pull request #99 from trojs/feature/processing-error
Browse files Browse the repository at this point in the history
Add the processing error
  • Loading branch information
w3nl authored Nov 27, 2024
2 parents 2b65db3 + 42dc540 commit c439d86
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 13 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ The object extends an Error object.

Types:

* AppError
* AuthenticationError
* AccessError
* NoContent
* NotFoundError
* NotImplementedError
* ServerError
* TimeoutError
* ValidationError
* RateLimitError
* NoContent (204)
* ValidationError (400)
* AuthenticationError (401)
* AccessError (403)
* NotFoundError (404)
* NotImplementedError (405)
* TimeoutError (408)
* ProcessingError (422)
* RateLimitError (429)
* AppError (500)
* ServerError (500)

You can send:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trojs/error",
"description": "Extended Errors",
"version": "4.1.0",
"version": "4.2.0",
"author": {
"name": "Pieter Wigboldus",
"url": "https://trojs.org/"
Expand All @@ -26,6 +26,7 @@
"src/no-content-error.js",
"src/not-found-error.js",
"src/not-implemented-error.js",
"src/processing-error.js",
"src/server-error.js",
"src/timeout-error.js",
"src/validation-error.js",
Expand Down
49 changes: 49 additions & 0 deletions src/__tests__/processing-error.unit.js
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)
})
})
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AccessError from './access-error.js'
import NoContentError from './no-content-error.js'
import NotFoundError from './not-found-error.js'
import NotImplementedError from './not-implemented-error.js'
import ProcessingError from './processing-error.js'
import ServerError from './server-error.js'
import TimeoutError from './timeout-error.js'
import ValidationError from './validation-error.js'
Expand All @@ -19,6 +20,7 @@ export {
NoContentError,
NotFoundError,
NotImplementedError,
ProcessingError,
ServerError,
TimeoutError,
ValidationError,
Expand Down
23 changes: 23 additions & 0 deletions src/processing-error.js
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

0 comments on commit c439d86

Please sign in to comment.