Skip to content

Instantly share code, notes, and snippets.

View jmcabrera's full-sized avatar

Juan Manuel CABRERA jmcabrera

View GitHub Profile
@jmcabrera
jmcabrera / errorflow.js
Created April 14, 2023 07:51
Example of error flow using exceptions
// Somewhere else, where a proper Exception Hierarchy is created
class SecurityError extends Error {}
class SystemError extends Error {}
class BusinessError extends Error {}
// In our store, where we subclass general exceptions as appropiate to our cases
class LockedUserError extends SecurityError {}
class DataAccessError extends SystemError {}
async function getUser(userId) {
if (userId == 'locked') throw new LockedUserError();

Keybase proof

I hereby claim:

  • I am jmcabrera on github.
  • I am juanma (https://keybase.io/juanma) on keybase.
  • I have a public key ASALUT49LNeFZfQ-9R5SFaxY0VP6ulQsUDIQs9v0qJg5bAo

To claim this, I am signing this object: