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