Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions assets/errorMessages.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const errorMessages = {
400: "The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).",
401: "The request has not been applied because it lacks valid authentication credentials for the target resource.",
403: "The server understood the request but refuses to authorize it.",
404: "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.",
408: "The server did not receive a complete request message within the time that it was prepared to wait.",
422: "The server understands the content type of the request entity, and the syntax of the request entity is correct but was unable to process the contained instructions.",
500: "The server encountered an unexpected condition that prevented it from fulfilling the request.",
502: "The server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.",
}
400: 'The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).',
401: 'The request has not been applied because it lacks valid authentication credentials for the target resource.',
403: 'The server understood the request but refuses to authorize it.',
404: 'The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.',
408: 'The server did not receive a complete request message within the time that it was prepared to wait.',
418: "I'm a teapot.",
422: 'The server understands the content type of the request entity, and the syntax of the request entity is correct but was unable to process the contained instructions.',
500: 'The server encountered an unexpected condition that prevented it from fulfilling the request.',
502: 'The server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.',
};

module.exports = errorMessages;
20 changes: 20 additions & 0 deletions src/errors/server/IAmATeapot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const DomainError = require('../DomainError');
const errorMessages = require('../../../assets/errorMessages');

/**
* 418: I'm a teapot
*
* Any attempt to brew coffee with a teapot should result in the error
* code "418 I'm a teapot". The resulting entity body MAY be short and
* stout
*
* Source: RFC2324 Section 2.3.2
*/

class IAmATeapot extends DomainError {
constructor(msg = errorMessages[418]) {
super(msg, 418);
}
}

module.exports = IAmATeapot;
1 change: 1 addition & 0 deletions src/errors/server/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
exports.BadGatewayError = require('./BadGatewayError');
exports.InternalServerError = require('./InternalServerError');
exports.IAmATeapot = require('./IAmATeapot');
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const throwError = (statusCode, msg) => {
throw new errors.RequestTimeoutError(msg);
case 404:
throw new errors.ResourceNotFoundError(msg);
case 418:
throw new errors.ImATeapot(msg);
case 422:
throw new errors.UnprocessableEntityError(msg);
case 502:
Expand Down
3 changes: 3 additions & 0 deletions tests/throwError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ describe('Testing throwError function', () => {
it('Should throw 404 Resource Not Found Error', () => {
expect(() => errors.throwError(404)).to.throw(errors.ResourceNotFoundError)
});
it('Should throw 418 I\'m a teapot Entity Error', () => {
expect(() => errors.throwError(418)).to.throw(errors.IAmATeapotError)
});
it('Should throw 422 Unprocessable Entity Error', () => {
expect(() => errors.throwError(422)).to.throw(errors.UnprocessableEntityError)
});
Expand Down