npm install --save fawait
fAwait
is a javascript library for working with the await
syntax for promises.
Wrap your promise in the fa
function, and provide errors you want to catch, and you'll receive an array you can unpack to those values. Any errors not specified will be thrown.
Read about it: Making Await More Functional in JavaScript
let [data, typeError, customBadThing] = await fa(promise, TypeError, BadThing);
fPromise
which is a heavier-weight promise solution.safe-await
which converts all errors to this functional form.go-for-it
which converts all non-native errors to this functional form.