2015-02-03 16:10:34 +08:00
|
|
|
import DS from 'ember-data';
|
2014-12-23 10:15:07 +08:00
|
|
|
import JsonApiAdapter from 'ember-json-api/json-api-adapter';
|
2015-01-23 10:18:21 +08:00
|
|
|
import config from '../config/environment';
|
2014-12-20 14:26:46 +08:00
|
|
|
|
2015-01-16 14:45:23 +08:00
|
|
|
export default JsonApiAdapter.extend({
|
2015-01-30 09:35:57 +08:00
|
|
|
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;
|
2015-01-30 09:35:57 +08:00
|
|
|
}
|
|
|
|
|
2015-01-16 14:45:23 +08:00
|
|
|
});
|