lykmapipo / sails-hook-validation

Custom validation error messages for sails model with i18n support
104 stars 29 forks source link

Does not work with blueprints #35

Closed yuri-karadzhov closed 8 years ago

yuri-karadzhov commented 8 years ago

Standard errors works with blueprints and return json error object, but sails-hook-validation return 500 error with no validation details by default.

lykmapipo commented 8 years ago

@yuri-karadzhov

What version of sails-hook-validation are you using?. If its latest version, may you please cross-check if you have setup model or local files correct.

yuri-karadzhov commented 8 years ago

Latest one and yes, i do set up models with right verification. I actually saw the right info in the console but on the client side there is only an 500 error.

einfallstoll commented 8 years ago

It actually worked sometime for me… I'm currently investigating the issue but expect it to be related to sails itself and not sails-hook-validation since the corresponding Errors object will be set on the error.

einfallstoll commented 8 years ago

I found the problem and was able to create a fix ( #40 ). There's a function in waterline that makes sure it's a WLError (waterline error) and if its not a WLError it'll "errorify" it (yep, that's the name of that function). Since the hook applies a patch to the toJSON function the error (which is a WLValidationError and not a WLError) will get overwritten at that point.

To make sure the errorify function just returns our patched error, I'll have to make sure the error is a valid WLError with a patched function.

TL;DR; my PR does the trick.

lykmapipo commented 8 years ago

@einfallstoll

Thanks for the fix.

lykmapipo commented 8 years ago

v0.4.5 is out with the fix