Skip to content

Utility used to wrap root async functions to avoid uncaught promise errors

Notifications You must be signed in to change notification settings

RafaelVidaurre/catch-async

Repository files navigation

Catch Async

Utility used to wrap root async functions to avoid uncaught promise errors to go silent.

catchAsync is intented for use in the root-level of an asyncronous chain of functions, basically avoiding the need of using try/catch and risking to leave silent errors in code.

API Documentation

Table of Contents

catchAsync

src/index.js:38-51

Returns an async function wrapped in a try catch function. It will by default log any error thrown in the async function unless a handleError function is provided. In that case it will instead call handleError

Parameters

  • asyncFunction Function
  • options Object? (optional, default {})
    • options.handleError Function? if this function is provided then catchAsync will call it instead of logging the error
    • options.logType String determines what logging method is used when an error is caught. Can be 'error', 'info', 'log' or 'warn' (optional, default 'error')

Returns Function Wrapped async function

About

Utility used to wrap root async functions to avoid uncaught promise errors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published