Giter Site home page Giter Site logo

node-caught's Introduction

node caught

npm install
Build Status Dependencies Status Known Vulnerabilities Downloads License

This module lets you attach empty rejcetion handlers to promises to avoid certain warnings that will be fatal errors in next versions of Node.

Since version 0.1.0 it supports TypeScript thanks to Wil Lee.

For a version for Deno, see: https://deno.land/x/caught

More info

Doing something like this:

var p = Promise.reject(0);

setTimeout(() => p.catch(e => console.error('caught')), 0);

will generate a lot of helpful warnings:

(node:13548) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 0
(node:13548) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13548) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)

This module lets you write:

var p = caught(Promise.reject(0));

setTimeout(() => p.catch(e => console.error('caught')), 0);

to ignore those warnings on a per-promise basis.

Use at your own risk.

Background

For more info see this answer on Stack Overflow:

Installation

To use in your projects:

npm install caught --save

Usage

var caught = require('caught');

var p = caught(Promise.reject(0));

Note that it is not the same as writing:

var p = Promise.reject(0).catch(() => {});

which would not return the original promise and wouldn't let you add catch handlers later.

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Rafał Pocztarski
Follow on GitHub Follow on Twitter
Follow on Stack Exchange

Contributors

License

MIT License (Expat). See LICENSE.md for details.

node-caught's People

Contributors

rsp avatar kourge avatar

Stargazers

Kuba Nejman avatar Wojtek Zdunski avatar  avatar Kirill Groshkov avatar Konrad (rootsher) Kowalski avatar Piotr Kowalski avatar Alexey Kozlov avatar Paul Melnikow avatar Andreas Kohn avatar Gabor Dolla avatar

Watchers

 avatar James Cloos avatar Paul Melnikow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.