Ghost/ghost/admin/app/services/ajax.js
Kevin Ansfield 0e603eb3d3 Don't swallow error details in ajax service
no issue
- keep the original `ember-ajax` behaviour rather than returning `false` when we hit an ajax error - we should only be using `normalizeErrorResponse` to normalize our error responses 😉
- ensures our application code has access to the returned status code for ajax errors
2016-04-04 14:19:05 +01:00

33 lines
882 B
JavaScript

import Ember from 'ember';
import AjaxService from 'ember-ajax/services/ajax';
const {inject, computed} = Ember;
export default AjaxService.extend({
session: inject.service(),
headers: computed('session.isAuthenticated', function () {
let session = this.get('session');
if (session.get('isAuthenticated')) {
let headers = {};
session.authorize('authorizer:oauth2', (headerName, headerValue) => {
headers[headerName] = headerValue;
});
return headers;
} else {
return [];
}
}),
normalizeErrorResponse(status, headers, payload) {
if (payload && typeof payload === 'object') {
payload.errors = payload.error || payload.errors || payload.message || undefined;
}
return this._super(status, headers, payload);
}
});