mercredi 5 octobre 2016

How to access Ember JSON API errors within template

I have the following route model hook:

model() {
    return this.store.query('page').then(
        (result) => { return result; },
        (errors) => { return errors; }
    );
}

I am returning a basic error in my API so I can determine the best way to display errors when the API fails while attempting to populate the initial model.

The response is:

{
    "errors": [
      {
         "detail": "Test",
         "source": {
             "pointer": "data/attributes/general"
         }
      }
    ]
}

This is caught and I am left with a model that contains an ErrorClass.

console error

I expect the error above to be accessed by the "general" key, and be able to do the following in a template:


    <div class="error msg_animate"></div>


But I am not able to access errors in this manner. It seems that my error response isn't being parsed correctly because I can access the errors as such:


    <div class="error msg_animate"> - </div>


This maps to the basic ErrorClass shown above and outputs:

Test - data/attributes/general

This is unexpected. What am I missing?




Aucun commentaire:

Enregistrer un commentaire