@sr258/express-http-custom-error
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Express HTTP Custom Error

Customizable HTTP Errors, compatible with es6 "throw" syntax, including a custom error handler for express APIs.

Installation

npm i @sr258/express-http-custom-error

Usage

Throwing an error:

const { BadRequest } = require('sr258@express-http-custom-error');

router.post('/signin', async (req, res, next) => {
    try {
        const { username } = req.body;
        if (!username) throw new BadRequest('Must include username.');
        ...
    } catch (err) {
        next(err);
    }
});

Using the error handler:

const { errorHandler } = require('@sr258/express-http-custom-error');
const app = express();

...

// All routers and other middleware must go before the error handler.
app.use(errorHandler);

/@sr258/express-http-custom-error/

    Package Sidebar

    Install

    npm i @sr258/express-http-custom-error

    Weekly Downloads

    2

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    60.1 kB

    Total Files

    11

    Last publish

    Collaborators

    • sr258-user