Closed NoRKin closed 9 years ago
@NoRKin I get you.
But I can tell that, you are serializing the whole error
object.
I think you were supposed to give JSON.stringify
a custom serializer.
See JSON.stringify
Am reviewing sails-hook-validation
codes too. May you please send a pull request with the above codes in test/serialization.spec.js
.
Thanks.
Hi @lykmapipo, I just got a problem while dealing with the validation errors in front end "sails": "~0.11.0"
, error.Errors
field will never appear because the definition of WLValidationError
(walterline validation error) are:
WLValidationError.prototype.toJSON =
WLValidationError.prototype.toPOJO =
function () {
return {
error: this.code,
status: this.status,
summary: this.reason,
model: this.model,
invalidAttributes: this.invalidAttributes
};
};
Any ideas?
@lanhaoxiang
Current custom error message have not been integrated to sails blueprint, thats why you are not able to receive error messages on your frontend.
You will have to override your blueprints for it to work.
@lanhaoxiang
Am looking for a way to fix this by patching WLValidationError
toJSON
and toPOJO
to allow for Errors
or errors
to be available when error is serialized
@NoRKin and @lanhaoxiang
Custom Errors
serialization is now available. Check for v0.4.0
Hi again,
I understand that error.Errors is added to the response, but custom error messages are never being sent.
This is because sails will serialize the error object to JSON. It removes at the same time the custom message you added.
Please test the spec below to understand what I mean. I serialize to JSON and parse again and you will see error.Errors will disappear.