Skip to content

Return errors as json objects instead of strings #722

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robbevp
Copy link
Member

@robbevp robbevp commented Feb 15, 2025

We currently have a mapping in config/locales/en.yml to convert error messages to keys, which we then look up in web's translations. I realised that by using @object.errors.errors we can just directly return the attributes of each error.

A response with errors would then become:

[
  {"attribute" => "title", "type" => "blank", "options" => {}},
  {"attribute" => "normalized_title", "type" => "blank", "options" => {}}
]

Options can be filled with more detail if needed. (For example, if we would have length validations: `{"attribute" => "title", "type" => "too_long", "options" => { "count" => 50 }

@chvp What do you think? Wanted to check this principle first, before I update the controllers, and js-client and web.

  • I've added tests relevant to my changes.

@robbevp robbevp added the enhancement New feature or request label Feb 15, 2025
@robbevp robbevp requested a review from chvp February 15, 2025 14:50
@robbevp robbevp self-assigned this Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant