pooleparty / wrap-error-handler

Utility used to catch unhandled exceptions in express route handlers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wrap-error-handler

Utility used to catch unhandled exceptions in express route handlers

Installation

Using npm:

npm install --save wrap-error-handler

Usage

import wrapErrorHandler from "wrap-error-handler";

function routeHandler(req, res, next) {
  const result = doSomethingThatMayThrowAnError();
  res.json(result);
}

const router = express.Router();

router.get('/', wrapErrorHandler(routeHandler));

API

wrapErrorHandler(fn)

fn

Type: function

Express handler function to wrap.

Development

Install dependencies

npm install

Run linter

npm run lint

Run tests

npm run tests

About

Utility used to catch unhandled exceptions in express route handlers

License:MIT License


Languages

Language:JavaScript 100.0%