A function to avoid UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning

License: MIT

Language: JavaScript

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:

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.


For more info see this answer on Stack Overflow:


To use in your projects:

npm install caught --save


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.


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


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



MIT License (Expat). See for details.

Project Statistics

Sourcerank 6
Repository Size 8.79 KB
Stars 7
Forks 3
Watchers 2
Open issues 0
Dependencies 0
Contributors 2
Tags 7
Last updated
Last pushed

Top Contributors See all

Rafał Pocztarski Wil Lee

Packages Referencing this Repo

Avoids UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning
Latest release 0.1.3 - Updated - 7 stars

Recent Tags See all

v0.1.3 November 21, 2019
v0.1.2 March 16, 2018
v0.1.1 March 13, 2017
v0.1.0 March 13, 2017
v0.0.3 December 01, 2016
v0.0.2 December 01, 2016
v0.0.1 December 01, 2016

Something wrong with this page? Make a suggestion

Last synced: 2019-11-21 00:47:32 UTC

Login to resync this repository