-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Improve 422 validation error responses #6050
Comments
I think we need to use something along the lines of the JSONAPI format. That's sort of where we were going but the spec didn't exist when we created what we have. Validation errors are kind of a special case, and they do warrant some extra love. Kind of neat that JSONAPI spec'd both 'parameter' and 'pointer' - not sure how easy implementing pointer will be, but we can definitely at least provide a 'property' name as the field a validation error belongs to not being returned is nothing more than an oversight in the I also very much want to start returning a custom error code with all of our errors. Need to come up with some sort of plan for what those look like. Any recommendations or resources for this would be great. I guess we should make use of our existing 'errorType' and perhaps do something like E.g. Harder to come up with something sane for general permissions errors etc: E.g. As for i18n, I am not sure if we need to think about that now. JSONAPI allows the title itself to be translated, I think we can leave it for now and allow those working on that project to determine which strategy they prefer? |
In terms of i18n, I think this issue can be closed in the same way as #5345 until we're ready to tackle #6525. @kevinansfield is there any other part of this that is still needed or would be useful to split out into a separate issue? If not please close this 😁 |
refs #8143 Sets soft limits for certain db fields: - `posts`: - `title`: 255 chars (current hard limit: 2,000 chars) - `meta_title`: 300 chars (current hard limit: 2,000 chars) - `meta_description`: 500 chars (current hard limit: 2,000 chars) - `users`: - `bio`: 200 chars (current hard limit: 65,535 chars) - `location`: 150 chars (current hard limit: 65,535 chars) - `meta_description`: 500 chars (current hard limit: 2,000 chars) - `meta_title`: 300 chars (current hard limit: 2,000 chars) - `tags`: - `description`: 500 chars (current hard limit: 65,535 chars) - `meta_title`: 300 chars (current hard limit: 2,000 chars) - `meta_description`: 500 chars (current hard limit: 2,000 chars) - same error message for isLength validator as for hard limits (more improvements are comming with #6050) - added more tests for importer - added dynamic translation key handling for validators errors (isLength is only supported atm)
This reference seems to be wrong. This issue contains two features/changes.
I agree to that.
Agree. I would like to suggest to rename the issue title to e.g. "JSON API format errors", remove the i18n suggestion and close with the later label. |
That's fine, the i18n note here was more of an aside and not meant to be the main focus of discussion. I think this issue is still relevant, we've mostly worked around it in Ghost-Admin by detecting certain words in the error message to display the error in the right place on a per-error basis (not particularly future-proof) or by showing a generic error/alert (poorer UX). As we implement larger features that require forms with more validation this may become more relevant as it will be harder to work around without compromises. |
Yeah understood, but even with pointers/codes the admin client would need to differentiate the validation errors? Could you show an example of code reduction/optimisation if we return pointers or codes? The issue is definitely relevant, but not sure about the priority and when we have time to tackle this 🙈 We could e.g. reference this issue in https://github.com/TryGhost/Team/issues/42 - just a suggestion. |
That's already built in to Ember Data, the errors would appear on the |
In any case, this can be closed with the |
Our current validation error format (not sure if this is consistent across the app?) looks like this:
This has a couple of issues when attempting to consume on the client side:
Due to the above issues we don't currently have anything in our Ember Data adapters to take the error response and normalize it so that the errors are automatically picked up by Ember Data/DS.Errors and made available on the relevant model object.
There are two formats that are widely used with Ember Data and have built-in support:
ActiveModelSerializer format:
JSON API format:
The JSON API format also allows for additional fields such as
code
for application-specific error codes or themeta
field that can contain completely custom data.i18n: If we are going to update our validation response format would it also be a good time to make accommodations for
i18n
support? To do so it would be best to provide a "key" for the localisation lookup, e.g. a genericvalidation.too_long
or a more specificpost.errors.title.too_long
.Perhaps the
meta
field would be best for that? That would allow us to both provide a localisation key and any other details that can be used for interpolation. For example:Could map nicely to the translation key:
"validation.too_long": "cannot be longer than {{max_chars}} characters"
I'd like to get some discussion started on which direction we'd like move towards for two main reasons:
The text was updated successfully, but these errors were encountered: