-
-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ServiceError.Field *string #2902
ServiceError.Field *string #2902
Conversation
f97969f
to
0adb9d1
Compare
This was related to my discussion: #2901 This PR allows my custom error formatter to build richer errors, transforming the standard {
"type": "validation_error",
"status": 422,
"request_id": "unknown",
"errors": [
{
"code": "invalid_field",
"message": "length of body.name must be greater or equal than 1 but got value \"\" (len=0)",
"source": {
"field": "name",
"pointer": "/name"
}
},
{
"code": "invalid_field",
"message": "length of body.description must be greater or equal than 1 but got value \"\" (len=0)",
"source": {
"field": "description",
"pointer": "/description"
}
}
]
} |
This looks great and could be really useful when writing custom error formatters. One thing to think about: could this introduce a backwards incompatible change? I think it should be OK given that this is adding fields and not changing or removing existing ones. |
Hey @raphael, sorry for the delay in getting back to you!
I don't think it can, as the original error struct should be unchanged. I've been quite careful to leave the original merging behaviour untouched, and all the new information is stored in the History only. So I think we should be fine to merge this as a non-breaking change? |
Makes sense. I see that the build is breaking because of a linting error:
Would you mind taking a look? You can run |
Yep, I'll take a look tomorrow. Thanks! |
Some errors generated by Goa are specific to fields- this commit ensures we populate `Field` of ServiceError when this is the case. An example would be when a field has a validation like `MinLength(1)` or similar, where the cause of the error is a specific part of the payload. It's often useful to retrieve this field, so that people can use this field to attach errors to the right form input, this being just one important use case. As part of this, we need to preserve the history of all virgin (un-merged) errors whenever we merge them, so we don't get a list of all individual errors with a gradually concatenated error message in each.
0adb9d1
to
68d3037
Compare
Tomorrow was extremely optimistic- I should have fixed that linting error now, though :) |
Looks great, thank you! |
Some errors generated by Goa are specific to fields- this commit ensures
we populate
Field
of ServiceError when this is the case.An example would be when a field has a validation like
MinLength(1)
orsimilar, where the cause of the error is a specific part of the payload.
It's often useful to retrieve this field, so that people can use this
field to attach errors to the right form input, this being just one
important use case.