mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
0e603eb3d3
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
33 lines
882 B
JavaScript
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);
|
|
}
|
|
});
|