flatAsync
flatAsync
a simple wrapper to use Async/Await calls without try/catch blocks.
Flat style pattern to handle errors.
Install
npm i flatasync --save
Use
ES6/7
import flatAsync from 'flatasync'
NodeJs
const flatAsync = require('flatasync');
Example
; const err response = await ; if err return console;if !response return console; // use response here
Before
You must use try/catch in Javascript's await
calls to handle errors from promise.
try const user = await ; if!user return ; catche return ;// another call based on user's datatry const post = await ; if!post return ; else return return ; catche return ;
After
flatAsync
wraps your await Promise or Method and returns errors/results in array [err, results]
.
;... let user post err; err user = await ;iferr || !user return ; err post = await ;iferr || !post return ; return ;