Skip to content

Commit

Permalink
Add AssertionFailedError
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoconceicao authored and rplopes committed Feb 5, 2020
1 parent 5bf7788 commit 4b09c78
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ try {

Below is the list of all available errors:

| Name | Code | Default message |
|:------------------------|:-----|:--------------------|
| BadRequestError | 400 | Bad Request |
| ConflictError | 409 | Conflict |
| ForbiddenError | 403 | Forbidden |
| GoneError | 410 | Gone |
| NotFoundError | 404 | Not Found |
| ServiceUnavailableError | 503 | Service Unavailable |
| UnauthorizedError | 401 | Unauthorized |
| ValidationFailedError | 400 | Validation Failed |
| Name | Code | Default message |
|:------------------------|:-----|:----------------------|
| AssertionFailedError | 500 | Internal Server Error |
| BadRequestError | 400 | Bad Request |
| ConflictError | 409 | Conflict |
| ForbiddenError | 403 | Forbidden |
| GoneError | 410 | Gone |
| NotFoundError | 404 | Not Found |
| ServiceUnavailableError | 503 | Service Unavailable |
| UnauthorizedError | 401 | Unauthorized |
| ValidationFailedError | 400 | Validation Failed |

## Usage

Expand Down
21 changes: 21 additions & 0 deletions src/errors/assertion-failed-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

/**
* Module dependencies.
*/

const HttpError = require('./http-error');

/**
* Export `AssertionFailedError`.
*/

module.exports = class AssertionFailedError extends HttpError {
/**
* Constructor.
*/

constructor(errors) {
super(500, 'Assertion Failed', { errors });
}
};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

module.exports = {
AssertionFailedError: require('./errors/assertion-failed-error'),
BadRequestError: require('./errors/bad-request-error'),
ConflictError: require('./errors/conflict-error'),
ForbiddenError: require('./errors/forbidden-error'),
Expand Down
20 changes: 20 additions & 0 deletions test/errors/assertion-failed-error_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

/**
* Module dependencies.
*/

const { AssertionFailedError } = require('../../src');
const test = require('../utils/test-http-error');

/**
* Test "Assertion Failed" error.
*/

describe('AssertionFailedError', () => {
test(AssertionFailedError, 500, 'Assertion Failed', false);

it('should set given `errors`', () => {
expect(new AssertionFailedError('foo').errors).toBe('foo');
});
});
6 changes: 6 additions & 0 deletions types/errors/assertion-failed-error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { HttpError } from './http-error';
export declare class AssertionFailedError extends HttpError {
errors?: object;

constructor(errors?: object);
}
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './errors/assertion-failed-error';
export * from './errors/bad-request-error';
export * from './errors/conflict-error';
export * from './errors/forbidden-error';
Expand Down

0 comments on commit 4b09c78

Please sign in to comment.