All Projects â†’ kbariotis â†’ Throw.js

kbariotis / Throw.js

Licence: mit
HTTP Error collection to use in your next REST API.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Throw.js

karma-go
Everything has a reason.
Stars: ✭ 15 (-94.49%)
Mutual labels:  errors
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
eth-rpc-errors
Ethereum RPC Errors
Stars: ✭ 78 (-71.32%)
Mutual labels:  errors
public
util toolkit for go.golang é€šç”šć‡œæ•°ćŒ…
Stars: ✭ 135 (-50.37%)
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
vcore
Common, utility packages for Go
Stars: ✭ 16 (-94.12%)
Mutual labels:  errors
chumsky
A parser library for humans with powerful error recovery.
Stars: ✭ 740 (+172.06%)
Mutual labels:  errors
ArgCheck.jl
Package for checking function arguments
Stars: ✭ 73 (-73.16%)
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
easybuggy4django
EasyBuggy clone built on Django
Stars: ✭ 44 (-83.82%)
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
rakered
The open source components from rake.red
Stars: ✭ 28 (-89.71%)
Mutual labels:  errors
failure
An error handling package for Go.
Stars: ✭ 24 (-91.18%)
Mutual labels:  errors
periskop
Exception Monitoring Service
Stars: ✭ 128 (-52.94%)
Mutual labels:  errors
go-errors
Flexible, general-purpose error handling for Go.
Stars: ✭ 17 (-93.75%)
Mutual labels:  errors
jsonerror
Makes Go error-handling a breeze!
Stars: ✭ 28 (-89.71%)
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].