DEV Community

Discussion on: Better error handling with async/await

Collapse
 
cafesanu profile image
Carlos Sanchez

Pretty neat solution!. The only thing I changed was that the data is returned in the second position and the error in the first position. This way the developer is forced to at least think about handling the error.

...
  .then((data) => [undefined, data])
  .catch((error) => Promise.resolve([error, undefined]));
...
Enter fullscreen mode Exit fullscreen mode