kbariotis / Throw.js
Licence: mit
HTTP Error collection to use in your next REST API.
Stars: â 272
Programming Languages
javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Projects that are alternatives of or similar to Throw.js
safe
đĄ PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: â 15 (-94.49%)
Mutual labels: errors
ono
Wrap errors without losing the original message, stack trace, or properties
Stars: â 87 (-68.01%)
Mutual labels: errors
errorlocate
Find and replace erroneous fields in data using validation rules
Stars: â 19 (-93.01%)
Mutual labels: errors
raise if
one liner `raise Exception if condition` for Python
Stars: â 15 (-94.49%)
Mutual labels: errors
tsfeatures
Calculates various features from time series data. Python implementation of the R package tsfeatures.
Stars: â 87 (-68.01%)
Mutual labels: errors
chumsky
A parser library for humans with powerful error recovery.
Stars: â 740 (+172.06%)
Mutual labels: errors
error-pages
đ§ Pretty server's error pages in the docker image & git repository
Stars: â 296 (+8.82%)
Mutual labels: errors
messaging
Conveniently issue messages, warnings, and errors
Stars: â 12 (-95.59%)
Mutual labels: errors
bugsnag-symfony
Bugsnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
Stars: â 42 (-84.56%)
Mutual labels: errors
go-errors
Flexible, general-purpose error handling for Go.
Stars: â 17 (-93.75%)
Mutual labels: errors
throw.js
An HTTP Error collection to use in your next REST API.
Installation
npm install --save throw.js
or
yarn add throw.js
Example
const express = require("express");
const app = express();
const { NotFound } = require("throw.js");
const logger = require("winston");
app.get("/", (req, res, next) => {
next(new NotFound());
});
app.use((err, req, res, next) => {
logger.error(err);
if (req.app.get("env") !== "development" && req.app.get("env") !== "test") {
delete err.stack;
}
res.status(err.statusCode || 500).json(err);
});
app.listen(3000);
Custom Errors
const { CustomError } = require("throw.js");
throw new CustomError(message, statusCode?, errorCode?, originalError?);
Parameters:
- message[optional]: Detailed message of this error
- statusCode[optional]: The HTTP Status number to return
- errorCode[optional]: An internal unique code identifier of this error
Stacking Errors
const { CustomError } = require("throw.js");
try {
// throws an error
} catch (e) {
// Pass the error as a parameter to keep its original stack trace
throw new CustomError(message, statusCode, errorCode, e);
}
Errors
All of the classes below have all parameters set up by default, based on RFC7231.
But you can override the message
and the errorCode
to fit your for personal needs.
400 Bad Request
BadRequest(message?, errorCode?, originalError?);
401 Unauthorized
Unauthorized(message?, errorCode?, originalError?);
402 Payment Required
PaymentRequired(message?, errorCode?, originalError?);
403 Forbidden
Forbidden(message?, errorCode?, originalError?);
404 Not Found
NotFound(message?, errorCode?, originalError?);
405 Method Not Allowed
MethodNotAllowed(message?, errorCode?, originalError?);
406 Not Acceptable
NotAcceptable(message?, errorCode?, originalError?);
407 Proxy Authentication Required
ProxyAuthenticationRequired(message?, errorCode?, originalError?);
408 Request Timeout
RequestTimeout(message?, errorCode?, originalError?);
409 Conflict
Conflict(message?, errorCode?, originalError?);
410 Gone
Gone(message?, errorCode?, originalError?);
422 Unprocessable Entity
UnprocessableEntity(message?, errorCode?, originalError?);
424 Failed Dependency
FailedDependency(message?, errorCode?, originalError?);
500 Internal Server Error
InternalServerError(message?, errorCode?, originalError?);
501 Not Implemented
NotImplemented(message?, errorCode?, originalError?);
502 Bad Gateway
BadGateway(message?, errorCode?, originalError?);
503 Service Unavailable
ServiceUnavailable(message?, errorCode?, originalError?);
504 Gateway Timeout
GatewayTimeout(message?, errorCode?, originalError?);
505 HTTP Version Not Supported
HttpVersionNotSupported(message?, errorCode?, originalError?);
511 Network Authentication Required
NetworkAuthenticationRequired(message?, errorCode?, originalError?);
TODO
- Implement more Error Classes
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].