Better (validation) errors rendering support
Closed this issue · 1 comments
The current (validation) errors rendering doesn't fully comply with the JSON API specification and it's inconsistent.
If the pointer can be matched to an element field then only the title
value is shown, but if that isn't the case then a "global" message is shown which contains both the title
and detail
values.
The specification states the following:
title: a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
detail: a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.
An example of an error object is provided on the JSON API examples page:
{
"errors": [
{
"status": "422",
"source": { "pointer": "/data/attributes/firstName" },
"title": "Invalid Attribute",
"detail": "First name must contain at least three characters."
}
]
}
This is the same "format" that is being generated by the Laravel JSON API package. Note that the so called "detail" of what actually went wrong is under the detail
key.
The problem here is that the pointer can be matched to a Trim field and then Trim displays the title
value near the firstName
element while we actually want to display the detail
value to the user.
Proposed solution:
a) standardize the validation display for both when the field can be matched from the pointer and when it can't be
b) in order to preserve backwards compatibility (as there are probably applications that rely on the current kinda broken behavior) create an option so that it can be chosen which keys should be displayed in both cases (when the pointer is matched or not).
@X-Coder264 added in version 0.56.0. Documented here https://trikoder.github.io/trim/core-concepts-and-api.html#validation-error-field