DEV Community

Discussion on: Errors Are Not Exceptions

Collapse
 
devinrhode2 profile image
Devin Rhode • Edited

Update: I recommend using an object style return. The array brackets are cute, but less useful. Positional args are fragile, and while this is only two, if you want to give a special error code or warning, then a simple new Error('asdf') can't represent either of these two (at least not very clearly).

So you may typically do:

return { error: new Error('asdf') }
Enter fullscreen mode Exit fullscreen mode

but you may occassionally:

return {
  warning: 'Update skipped. Provided data is the same.',
  errorCode: 'update_skipped',
}
Enter fullscreen mode Exit fullscreen mode

Note to self: I don't think I have any code that actually uses this idea. Was just a pure idea.