Better API error handling

This commit is contained in:
Toby Zerner
2015-05-18 18:13:16 +09:30
parent 9f42fbe450
commit 1b4b03356a
9 changed files with 74 additions and 30 deletions

View File

@ -13,7 +13,7 @@ export default class Alert extends Component {
var message = attrs.message;
delete attrs.message;
var controlItems = attrs.controls.slice() || [];
var controlItems = attrs.controls ? attrs.controls.slice() : [];
delete attrs.controls;
if (attrs.dismissible || attrs.dismissible === undefined) {

View File

@ -23,8 +23,8 @@ export default class Alerts extends Component {
var index = this.components.indexOf(component);
if (index !== -1) {
this.components.splice(index, 1);
m.redraw();
}
m.redraw();
}
clear() {

View File

@ -1,4 +1,5 @@
import ItemList from 'flarum/utils/item-list';
import Alert from 'flarum/components/alert';
class App {
constructor() {
@ -14,6 +15,14 @@ class App {
document.title = (title ? title+' - ' : '')+this.config['forum_title'];
}
handleApiErrors(response) {
this.alerts.clear();
response.errors.forEach(error =>
this.alerts.show(new Alert({ type: 'warning', message: error.detail }))
);
}
route(name, params) {
var url = this.routes[name][0].replace(/:([^\/]+)/g, function(m, t) {
var value = params[t];