@simpleview/express-async-handler
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@simpleview/express-async-handler

Wrap an express handler to properly handle async errors. Same as npm express-async-handler but with better typing.

Installation

npm install @simpleview/express-async-handler

Use

Basic Example

import express from "express";
import { asyncWrap } from "@simpleview/express-async-handler";

const app = express();
app.get("/", asyncWrap(async function(req, res, next) {
    // any errors thrown will be passed on to next() automatically
});

With custom typing

In order to get rich typing you'll want to setup some helper types. There are two primary needs for custom typing.

  • Customization of the Application locals (req.app.locals, res.app.locals).
  • Customization of the Request (req.query, req.body, req.session).

There is a full example in examples/custom_typing.

Readme

Keywords

none

Package Sidebar

Install

npm i @simpleview/express-async-handler

Weekly Downloads

148

Version

1.0.2

License

ISC

Unpacked Size

12.5 kB

Total Files

14

Last publish

Collaborators

  • paul.riding
  • mcutshall
  • georgeyb-sv
  • sloutrel
  • dlford
  • korychinn_sv
  • sv-mikael
  • actionawesome
  • arkmuntasser
  • leandrodalmassoglb
  • kristian.gonzalez
  • davidlpons
  • csarantidessv
  • mikesan789
  • owenallenaz
  • qman33
  • svjoshua
  • mkes99
  • colin.booen
  • ssmith_sv
  • aglazebrook
  • rmaynes