fix Zabbix API error message

This commit is contained in:
Alexander Zobnin
2017-10-22 11:37:17 +03:00
parent 538589b99b
commit df64c190e2
8 changed files with 24 additions and 31 deletions

View File

@@ -582,13 +582,13 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
return { return {
status: "error", status: "error",
title: error.message, title: error.message,
message: error.data message: error.message
}; };
} else if (error.data && error.data.message) { } else if (error.data && error.data.message) {
return { return {
status: "error", status: "error",
title: "Connection failed", title: "Connection failed",
message: error.data.message message: "Connection failed: " + error.data.message
}; };
} else { } else {
return { return {

File diff suppressed because one or more lines are too long

View File

@@ -100,8 +100,6 @@ System.register(['angular'], function (_export, _context) {
// Success // Success
return response.data.result; return response.data.result;
}).catch(function () {
return Promise.reject(new ZabbixAPIError({ data: "Connection Error" }));
}); });
} }
}, { }, {
@@ -127,16 +125,16 @@ System.register(['angular'], function (_export, _context) {
function ZabbixAPIError(error) { function ZabbixAPIError(error) {
_classCallCheck(this, ZabbixAPIError); _classCallCheck(this, ZabbixAPIError);
this.code = error.code; this.code = error.code || null;
this.name = error.data; this.name = error.message || "";
this.message = error.data; this.data = error.data || "";
this.data = error.data; this.message = "Zabbix API Error: " + this.name + " " + this.data;
} }
_createClass(ZabbixAPIError, [{ _createClass(ZabbixAPIError, [{
key: 'toString', key: 'toString',
value: function toString() { value: function toString() {
return this.name + ": " + this.message; return this.name + " " + this.data;
} }
}]); }]);

File diff suppressed because one or more lines are too long

View File

@@ -466,13 +466,13 @@ var ZabbixAPIDatasource = function () {
return { return {
status: "error", status: "error",
title: error.message, title: error.message,
message: error.data message: error.message
}; };
} else if (error.data && error.data.message) { } else if (error.data && error.data.message) {
return { return {
status: "error", status: "error",
title: "Connection failed", title: "Connection failed",
message: error.data.message message: "Connection failed: " + error.data.message
}; };
} else { } else {
return { return {

View File

@@ -83,8 +83,6 @@ var ZabbixAPICoreService = function () {
// Success // Success
return response.data.result; return response.data.result;
}).catch(function () {
return Promise.reject(new ZabbixAPIError({ data: "Connection Error" }));
}); });
} }
@@ -125,16 +123,16 @@ var ZabbixAPIError = exports.ZabbixAPIError = function () {
function ZabbixAPIError(error) { function ZabbixAPIError(error) {
_classCallCheck(this, ZabbixAPIError); _classCallCheck(this, ZabbixAPIError);
this.code = error.code; this.code = error.code || null;
this.name = error.data; this.name = error.message || "";
this.message = error.data; this.data = error.data || "";
this.data = error.data; this.message = "Zabbix API Error: " + this.name + " " + this.data;
} }
_createClass(ZabbixAPIError, [{ _createClass(ZabbixAPIError, [{
key: 'toString', key: 'toString',
value: function toString() { value: function toString() {
return this.name + ": " + this.message; return this.name + " " + this.data;
} }
}]); }]);

View File

@@ -378,13 +378,13 @@ class ZabbixAPIDatasource {
return { return {
status: "error", status: "error",
title: error.message, title: error.message,
message: error.data message: error.message
}; };
} else if (error.data && error.data.message) { } else if (error.data && error.data.message) {
return { return {
status: "error", status: "error",
title: "Connection failed", title: "Connection failed",
message: error.data.message message: "Connection failed: " + error.data.message
}; };
} else { } else {
return { return {

View File

@@ -53,7 +53,7 @@ class ZabbixAPICoreService {
datasourceRequest(requestOptions) { datasourceRequest(requestOptions) {
return this.backendSrv.datasourceRequest(requestOptions) return this.backendSrv.datasourceRequest(requestOptions)
.then(response => { .then((response) => {
if (!response.data) { if (!response.data) {
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"})); return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
} else if (response.data.error) { } else if (response.data.error) {
@@ -64,9 +64,6 @@ class ZabbixAPICoreService {
// Success // Success
return response.data.result; return response.data.result;
})
.catch(() => {
return Promise.reject(new ZabbixAPIError({data: "Connection Error"}));
}); });
} }
@@ -94,14 +91,14 @@ class ZabbixAPICoreService {
// Define zabbix API exception type // Define zabbix API exception type
export class ZabbixAPIError { export class ZabbixAPIError {
constructor(error) { constructor(error) {
this.code = error.code; this.code = error.code || null;
this.name = error.data; this.name = error.message || "";
this.message = error.data; this.data = error.data || "";
this.data = error.data; this.message = "Zabbix API Error: " + this.name + " " + this.data;
} }
toString() { toString() {
return this.name + ": " + this.message; return this.name + " " + this.data;
} }
} }