DEV: Provide a nicer error when JSON is malformed

This is very useful for development. It will give a much nicer error if
the JSON that comes back from the server is missing a required key.
This commit is contained in:
Robin Ward 2019-11-12 13:04:14 -05:00
parent c9bd463e9d
commit 4422d9a4bf
1 changed files with 7 additions and 0 deletions

View File

@ -219,6 +219,13 @@ export default EmberObject.extend({
_resultSet(type, result, findArgs) {
const adapter = this.adapterFor(type);
const typeName = underscore(this.pluralize(adapter.apiNameFor(type)));
if (!result[typeName]) {
// eslint-disable-next-line no-console
console.error(`JSON response is missing \`${typeName}\` key`, result);
return;
}
const content = result[typeName].map(obj =>
this._hydrate(type, obj, result)
);