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.

model.errorsis an array then eachingmodel.errors.generaldoesn't really make sense, right?{{#if model.errors.general}} <div class="error msg_animate">{{model.errors.general.message}} </div>{{/if}}` I'd expect this to work based on other things I've read on SO. I could be way off of course.model.errorsis a list of errors so you can access the first one withmodel.errors[0]and if the first error had a general key you could access it likemodel.errors[0].general— handlebars each is designed to be used with list-like structures, not map-like structures{{log 'model.errors - ' model.errors}}..that would print object in console. that should explain a lot.detailandsource -> pointerkeys. I would expect to be able to access the errors from my model as described here. However, that does not work. Is the issue the fact that I am returning an error from my model() hook initially? Should I be using an error substate instead of my initial template?