Skip to content

taewdy/async-error-catcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Error Catcher

Usage

Wrapping one function in a object

  • Without the Catcher
const fetch = require('fetch');

try {
  const result = fetch.get('http://localhost:3000/users');
} catch (e) {
  console.log(e)
}
  • With the catcher
const { catcher } = require('async-error-catcher');
const fetch = require('fetch');

const result = catcher(fetch.get)('http://localhost:3000/users')

Wrapping multiple function in a object

  • For example, fetch has multiple async functions.
fetch = {
  get: () => {},
  post: () => {},
  patch: () => {},
}
const { catchers } = require('async-error-catcher');

const wrappedFetch = catchers(fetch);

wrappedFetch.get('http://localhost:3000/users');
wrappedFetch.post('http://localhost:3000/users');
wrappedFetch.patch('http://localhost:3000/users');

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published