Closed fabrik42 closed 10 years ago
Thanks for contributing. I implemented a modified version of your idea. Instead of using a single error class, I created a class for each type of error. To stay backwards compatible, these classes inherit from ::ArgumentError
as you suggested. Instead of an #errors
method, I implemented a #to_hash
method for all error classes.
Nice, thanks!
I want to use smart properties to validate/sanitize hashes. However, if this is connected to a user facing interface, you usually want to provide some kind of feedback, when the property interfaces are not satisfied.
So I added a custom exception class, called
SmartProperties::ArgumentError
, that has an additional property callederrors
. It contains a hash of the structureinvalid_field => error explanation
that can be used e.g. for rendering a JSON error response.Please note that
SmartProperties::ArgumentError
inherits fromArgumentError
to keep backwards compatibility.Cheers!