mirror of
https://github.com/flarum/core.git
synced 2025-07-21 08:41:17 +02:00
Better handling of AJAX errors
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
|
import DS from 'ember-data';
|
||||||
import JsonApiAdapter from 'ember-json-api/json-api-adapter';
|
import JsonApiAdapter from 'ember-json-api/json-api-adapter';
|
||||||
import config from '../config/environment';
|
import config from '../config/environment';
|
||||||
|
|
||||||
export default JsonApiAdapter.extend({
|
export default JsonApiAdapter.extend({
|
||||||
|
|
||||||
// Todo: make this loaded via an environment variable or something
|
|
||||||
host: config.apiURL,
|
host: config.apiURL,
|
||||||
|
|
||||||
// We can get rid of this after
|
// We can get rid of this after
|
||||||
@@ -13,6 +12,22 @@ export default JsonApiAdapter.extend({
|
|||||||
store.metaForType(type, payload.meta);
|
store.metaForType(type, payload.meta);
|
||||||
delete payload.meta;
|
delete payload.meta;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
@@ -88,11 +88,14 @@ export default Ember.ObjectController.extend(Ember.Evented, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
function(reason) {
|
function(reason) {
|
||||||
var message = AlertMessage.create({
|
var errors = reason.errors;
|
||||||
type: 'warning',
|
for (var i in reason.errors) {
|
||||||
message: reason.errors[0].detail
|
var message = AlertMessage.create({
|
||||||
});
|
type: 'warning',
|
||||||
controller.get('controllers.application').send('alert', message);
|
message: reason.errors[i]
|
||||||
|
});
|
||||||
|
controller.get('controllers.application').send('alert', message);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(function() {
|
.finally(function() {
|
||||||
composer.set('content.loading', false);
|
composer.set('content.loading', false);
|
||||||
|
Reference in New Issue
Block a user