await-plz
v1.2.1
Published
A wrapper for usage in await to get prettier error handling. No more dirty try-catch blocks with anti-pattern `let` and such!
Downloads
132
Readme
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
)!