Skip to content
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

ActiveModelAdapter camelizes keys for errors on 422 #3030

Merged
merged 3 commits into from Apr 29, 2015
Merged

ActiveModelAdapter camelizes keys for errors on 422 #3030

merged 3 commits into from Apr 29, 2015

Conversation

ghost
Copy link

@ghost ghost commented Apr 27, 2015

Fields are not currently camelized in the model's errors object e.g.

pilot.errors.first_name

should be

pilot.errors.firstName

There is already test for this behavior but because of the way InvalidError and Ember.inspect are implemented the test passes when it shouldn't do.

ActiveModelAdapter now passes the errors hash directly to InvalidError as is expected according to the docs. This assumes that the 422 provides JSON of the form

{
  errors: {
    first_name: ['is too long']
  }
}

as is standard in active model. If errors is not present in the JSON response, active model adapter will continue to behave as it did before.

Ben Holmes added 3 commits April 27, 2015 14:13
Expects the error keys to be top-level:

    For Ember Data to correctly map errors to their corresponding
    properties on the model, Ember Data expects each error to be
    namespaced under a key that matches the property name.

    return Ember.RSVP.reject(new DS.InvalidError({
            title: ['Must be unique'],
            content: ['Must not be blank'],
          }));

This was actually causing tests to pass that shouldn't have because of the
simple nature of `Ember.inspect`. E.g. comparing strings:

    "Error: The backend rejected the commit because it was invalid: {errors: [object Object]}"
If a response is provided without an errors object then Ember Data will
still work like it used to.
Error keys were arriving on models with underscores e.g.

    human.errors.first_name

Addresses the test which was incorrectly passing
fivetanley added a commit that referenced this pull request Apr 29, 2015
ActiveModelAdapter camelizes keys for errors on 422
@fivetanley fivetanley merged commit 6d47319 into emberjs:master Apr 29, 2015
@fivetanley
Copy link
Member

awesome, thanks!

@ghost ghost deleted the ams_camelized_errors branch April 29, 2015 21:56
@pangratz
Copy link
Member

pangratz commented May 2, 2015

@fivetanley @bdvholmes shouldn't camelCasing they keys be a concern of the serializer, and be done inside extractErrors (see http://git.io/vJ0Ey)?

@igorT
Copy link
Member

igorT commented May 4, 2015

@pangratz is correct, this PR seems wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants