Nice!
FYI: You might still need try..catch though, the wrapper catches asynchronous errors but if inside callApi anything you call issues a "standard" error that exception will bubble up to the user.
callApi
const callApi = async () => { const { error, data } = await wrapper(fetchData(2000, false)); callAFunctionThatDividesByZero() if (!error) { console.info(data); return; } console.error(error); }
Thanks! :) And Yeah on regular exceptions I would need a catch but I was focusing on the API part only! :)
I like it, it reminds me of how Go does error handling :D
I still haven't worked with Go yet 🙈 planning to start soon.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice!
FYI: You might still need try..catch though, the wrapper catches asynchronous errors but if inside
callApi
anything you call issues a "standard" error that exception will bubble up to the user.Thanks! :) And Yeah on regular exceptions I would need a catch but I was focusing on the API part only! :)
I like it, it reminds me of how Go does error handling :D
I still haven't worked with Go yet 🙈 planning to start soon.