TritonDataCenter / node-verror

Rich JavaScript errors
MIT License
1.18k stars 61 forks source link

Alternative to wrapping errors #12

Closed yangvz closed 8 years ago

yangvz commented 10 years ago

Wrapping errors feels wrong. How about this:

// HTTP errors
err.module = "RFCXXXX"; // or say "HTTP1.1"
err.code = "XXXX";
// say registering users
if (err.code == '23505') { err.module = "RegisterUser"; err.code = "EMAIL_EXISTS"; }
else { err.module = "PostgreSQL"; }

And the request handler renders appropriately using first err.stand then err.code. Both values can be overwritten. All you do is provide almost all common error standards like http.STATUS_CODES does, say pg.STATUS_CODES etc.

davepacheco commented 10 years ago

I don't really follow. I like the extra information about what happened (module, programmatic codes, etc.), but I don't understand what the code is supposed to be doing (what's 23505?), what "err.stand" is, or why any of this isn't orthogonal to wrapping errors? The point of wrapping is for accretive error messages: a request may have failed because of an error to a backend service, which failed because of a problem talking to a database, which failed because some resource limit was exceeded, and so on. The point is to preserve all of that information for debugging.

davepacheco commented 8 years ago

Closing this, but feel free to reopen with clarification.