jeudi 26 janvier 2017

Assertion Failed: `AdapterError` expects json-api formatted errors array

After reading Handling Errors with Ember Data and numerous other tips and tricks on how to solve error handling in Ember JS, I still am not able to figure out what is wrong with my code.

For starters, I have a user model like so:

import DS from 'ember-data';

export default DS.Model.extend({
    firstName: DS.attr('string'),
    surName: DS.attr('string'),
    email: DS.attr('string'),
    plainPassword: DS.attr('string')
});

Obviously I do not return a password from the server, but I assume it is needed in the model to send it from the registration form. Anyway, onward.

The form template looks like this:

<!-- start Register -->
<div class="container-fluid">
    <form name="form_register"  class="form-register" novalidate="novalidate">
        <div class="col-md">
            <label class="el-input-wrap">
                First Name
                
            </label>
            <label class="el-input-wrap">
                Last Name
                
            </label>
        </div>
        <div class="col-md">
            <label class="el-input-wrap">
                Email
                
            </label>
            <label class="el-input-wrap">
                Password
                
            </label>
        </div>
        <div class="col">
            <label class="el-checkbox">
                By registering I agree to the terms and conditions
            </label>
        </div>
        <button type="submit" class="el-btn mod-full-w">REGISTER</button>
    </form>
</div>
<!-- end Register -->

Next I have the registration controller that handle the registration form:

import Ember from 'ember';

export default Ember.Controller.extend({
    actions: {
        cancel() {
            this.get('model').deleteRecord();
            return true;
        },

        submit() {
            var user = this.get('model');
            user.save().then(
                () => this.transitionToRoute('register')
            ).catch((adapterError) => {
                console.log(adapterError);
            });
        }
    }
});

Here, I have tried to console.log errors, errors.firstName and so on. But no errors show.

The adapterError tells me the error format is not in JSON API format. But from what I can see, it is:

{
    "errors": {
        "source": {
            "pointer": "user\/email"
        },
        "detail": "user.email.not_blank"
    }
}

Lastly, I am using the RESTAdapter in adapters/application.js:

import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DS.RESTAdapter.extend(DataAdapterMixin, {
    namespace: 'app_dev.php/api',
    authorizer: 'authorizer:token', //or authorizer: 'authorizer:jwt'
});

For the life of me, I can not figure out what is wrong. I would very much appreciate any help or pointers. Thank you.




Aucun commentaire:

Enregistrer un commentaire