Skip to content

Commit

Permalink
triggers panel: fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Oct 18, 2018
1 parent 995811d commit a3f5090
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export class ZabbixAPIConnector {
.then(() => this.request(method, params));
}
} else {
// Handle API errors
let message = error.data ? error.data : error.statusText;
return Promise.reject(message);
return Promise.reject(error);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/datasource-zabbix/zabbix/zabbix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const REQUESTS_TO_CACHE = [

const REQUESTS_TO_BIND = [
'getHistory', 'getTrend', 'getMacros', 'getItemsByIDs', 'getEvents', 'getAlerts', 'getHostAlerts',
'getAcknowledges', 'getITService', 'getVersion', 'login'
'getAcknowledges', 'getITService', 'getVersion', 'login', 'acknowledgeEvent'
];

export class Zabbix {
Expand Down
36 changes: 20 additions & 16 deletions src/panel-triggers/triggers_panel_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ export class TriggerPanelCtrl extends PanelCtrl {
this.events.on('refresh', this.onRefresh.bind(this));
}

setPanelError(err, defaultError) {
const defaultErrorMessage = defaultError || "Request Error";
this.inspector = { error: err };
this.error = err.message || defaultErrorMessage;
if (err.data) {
if (err.data.message) {
this.error = err.data.message;
}
if (err.data.error) {
this.error = err.data.error;
}
}

this.events.emit('data-error', err);
console.log('Panel data error:', err);
}

initDatasources() {
let promises = _.map(this.panel.datasources, (ds) => {
// Load datasource
Expand Down Expand Up @@ -161,18 +178,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
return;
}

this.error = err.message || "Request Error";
if (err.data) {
if (err.data.message) {
this.error = err.data.message;
}
if (err.data.error) {
this.error = err.data.error;
}
}

this.events.emit('data-error', err);
console.log('Panel data error:', err);
this.setPanelError(err);
});
}

Expand Down Expand Up @@ -459,16 +465,14 @@ export class TriggerPanelCtrl extends PanelCtrl {
return Promise.reject({message: 'You have no permissions to acknowledge events.'});
}
if (eventid) {
return datasource.zabbix.zabbixAPI.acknowledgeEvent(eventid, ack_message);
return datasource.zabbix.acknowledgeEvent(eventid, ack_message);
} else {
return Promise.reject({message: 'Trigger has no events. Nothing to acknowledge.'});
}
})
.then(this.onRefresh.bind(this))
.catch((err) => {
this.error = err.message || "Acknowledge Error";
this.events.emit('data-error', err);
console.log('Panel data error:', err);
this.setPanelError(err);
});
}

Expand Down

0 comments on commit a3f5090

Please sign in to comment.