deno caught
This module lets you attach empty rejcetion handlers to promises to avoid errors when we want to handle rejections asynchronously.
It is a port of caught
for Node, see: https://github.com/rsp/node-caught
More info
Doing something like this:
const p = Promise.reject(0);
setTimeout(() => p.catch(e => console.error('caught')), 0);
will result in the program terminating with an error:
error: Uncaught 0
This module lets you write:
const p = caught(Promise.reject(0));
setTimeout(() => p.catch(e => console.error('caught')), 0);
to avoid those errors on a per-promise basis.
Use at your own risk.
Background
For more info see this answer on Stack Overflow:
Usage
import { caught } from 'https://deno.land/x/caught/mod.ts';
const p = caught(Promise.reject(0));
Note that it is not the same as writing:
const 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
Contributors
- Wil Lee (added TypeScript support in the original caught for Node)
License
MIT License (Expat). See LICENSE.md for details.