framework/ember/app/adapters/application.js

33 lines
941 B
JavaScript
Raw Normal View History

2015-02-03 16:10:34 +08:00
import DS from 'ember-data';
import JsonApiAdapter from 'ember-json-api/json-api-adapter';
import config from '../config/environment';
2014-12-20 14:26:46 +08:00
export default JsonApiAdapter.extend({
host: config.apiURL,
// We can get rid of this after
// https://github.com/kurko/ember-json-api/pull/59 is merged.
extractMeta: function(store, type, payload) {
if (payload && payload.meta) {
store.metaForType(type, payload.meta);
delete payload.meta;
}
2015-02-03 16:10:34 +08:00
},
ajaxError: function(jqXHR) {
var errors = this._super(jqXHR);
if (errors instanceof DS.InvalidError) {
var newErrors = {};
for (var i in errors.errors) {
var error = errors.errors[i];
newErrors[error.path] = error.detail;
}
errors = new DS.InvalidError(newErrors);
} else if (errors instanceof JsonApiAdapter.ServerError) {
// @todo show an alert message
console.log(errors);
}
return errors;
}
});