await-plz

1.2.1 • Public • Published

await pls

Are you sick and tired of Trying and Catching

GET AWAIT-PLZ TODAY

Add the dependency:

yarn add await-plz

Import the script:

import plz from 'await-plz';

await-plz is a simple library used to wrap your promises before sending them to be awaited. By utilizing some simple then-catch logic, it returns an array with two values: [err, response]. This makes catching errors alot leaner:

Before

  let someVariable;
  try {
    someVariable = await somePromiseToGetVariable();
  } catch (error) {
    console.error('Failed to get some variable, error:');
    console.error(error);
  }

After

  const [err, response] = await plz(somePromiseToGetVariable);
  if (err) console.error('Failed to get some variable, error:', err);
  if (!response) return console.log('No variable found');
  
  // Do what you wanna do!

It even handles Response type of reponses (via for example fetch)!

Readme

Keywords

none

Package Sidebar

Install

npm i await-plz

Weekly Downloads

59

Version

1.2.1

License

MIT

Unpacked Size

2.27 kB

Total Files

3

Last publish

Collaborators

  • herge