clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

Produce dynogels-specific errors #73

Closed cdhowie closed 7 years ago

cdhowie commented 7 years ago

There are multiple places in dynogels where a new Error object is thrown or passed to a callback in error position. We should use a dynogels-specific error instead of the built-in Error type so that dynogels errors can be distinguished from other errors in error-handling code.

I am particularly singling this line out. It makes it very difficult to automatically and reliably determine that this error is the result of a schema check. In our application, we detect Joi errors and automatically react by responding with an HTTP error code of 422 (unprocessable entity) but we are completely unable to do that with these errors since the Joi validation error is masked behind an untyped error.