From 3ee15a0a7ee0ac84424da0e6f2b47104f9d04e1b Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sat, 23 Jan 2016 18:31:19 +0300 Subject: [PATCH] Handle "Session terminated..." error. --- plugins/datasource-zabbix/zabbixAPI.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/datasource-zabbix/zabbixAPI.js b/plugins/datasource-zabbix/zabbixAPI.js index 73d7a88..8f12599 100644 --- a/plugins/datasource-zabbix/zabbixAPI.js +++ b/plugins/datasource-zabbix/zabbixAPI.js @@ -32,7 +32,21 @@ function (angular, _) { p.request = function(method, params) { var self = this; if (this.auth) { - return ZabbixAPIService._request(this.url, method, params, this.requestOptions, this.auth); + return ZabbixAPIService._request(this.url, method, params, this.requestOptions, this.auth) + .then(function(result) { + return result; + }, + + // Handle errors + function(error) { + if (error.message === "Session terminated, re-login, please.") { + return ZabbixAPIService.login(self.url, self.username, self.password, self.requestOptions) + .then(function(auth) { + self.auth = auth; + return ZabbixAPIService._request(self.url, method, params, self.requestOptions, self.auth); + }); + } + }); } else { // Login first