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.
I expect the error above to be accessed by the "general" key, and be able to do the following in a template:
{{#each model.errors.general as |error|}}
<div class="error msg_animate">{{error.message}}</div>
{{/each}}
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:
{{#each model.errors as |error index|}}
<div class="error msg_animate">{{error.detail}} - {{error.source.pointer}}</div>
{{/each}}
This maps to the basic ErrorClass shown above and outputs:
Test - data/attributes/general
This is unexpected. What am I missing?
UPDATED INFORMATION
I have the following that works in another route. The difference being that it returns errors after attempting to save a model (rather than directly from the model() hook:
template.hbs
{{#each model.errors as |error|}}
<div class="error msg_animate">{{error.message}}</div>
{{/each}}
route.js
actions: {
submit: function(model){
model.save().then((resp) => {
this.transitionTo('admin.page-edit', resp.data.attributes.permalink);
}, function(resp){
// errors show on template
});
}
}
I am thoroughly confused as to the difference. Both responses from my API seem exactly the same in terms of format.