Monday, 4 May 2020

Created a library to abstract some use cases of try/catch blocks. What do you think about it?

Sometimes I was writing some code like that:let result = null; try { result = doStuff(a, b); } catch (error) { console.log(error); return; } // Do more stuff with `result`... And I really don't like doing that. So I created errou, a NPM package that abstracts try/catch blocks.So you would write:const call = errou(doStuff, a, b); if (!call.ok) { console.log(call.error); return; } // Do more stuff with `call.data`... You could also write:const call = errou(() => doStuff(a, b)); Thoughts?Please give a star in the repository. Any contributions are welcome. :)

Submitted May 04, 2020 at 04:31PM by lffg

No comments:

Post a Comment