Refactor: improved working with promises in testDatasource() method.
This commit is contained in:
@@ -8,6 +8,7 @@ import DataProcessor from './DataProcessor';
|
|||||||
import './zabbixAPI.service.js';
|
import './zabbixAPI.service.js';
|
||||||
import './zabbixCache.service.js';
|
import './zabbixCache.service.js';
|
||||||
import './queryProcessor.service.js';
|
import './queryProcessor.service.js';
|
||||||
|
import {ZabbixAPIError} from './zabbixAPICore.service.js';
|
||||||
|
|
||||||
class ZabbixAPIDatasource {
|
class ZabbixAPIDatasource {
|
||||||
|
|
||||||
@@ -257,38 +258,34 @@ class ZabbixAPIDatasource {
|
|||||||
* @return {object} Connection status and Zabbix API version
|
* @return {object} Connection status and Zabbix API version
|
||||||
*/
|
*/
|
||||||
testDatasource() {
|
testDatasource() {
|
||||||
|
let zabbixVersion;
|
||||||
return this.zabbixAPI.getVersion()
|
return this.zabbixAPI.getVersion()
|
||||||
.then(version => {
|
.then(version => {
|
||||||
return this.zabbixAPI.login()
|
zabbixVersion = version;
|
||||||
.then(auth => {
|
return this.zabbixAPI.login();
|
||||||
if (auth) {
|
})
|
||||||
return {
|
.then(() => {
|
||||||
status: "success",
|
return {
|
||||||
title: "Success",
|
status: "success",
|
||||||
message: "Zabbix API version: " + version
|
title: "Success",
|
||||||
};
|
message: "Zabbix API version: " + zabbixVersion
|
||||||
} else {
|
};
|
||||||
return {
|
})
|
||||||
status: "error",
|
.catch(error => {
|
||||||
title: "Invalid user name or password",
|
if (error instanceof ZabbixAPIError) {
|
||||||
message: "Zabbix API version: " + version
|
return {
|
||||||
};
|
status: "error",
|
||||||
}
|
title: error.message,
|
||||||
}, error => {
|
message: error.data
|
||||||
return {
|
};
|
||||||
status: "error",
|
} else {
|
||||||
title: error.message,
|
|
||||||
message: error.data
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}, error => {
|
|
||||||
console.log(error);
|
|
||||||
return {
|
return {
|
||||||
status: "error",
|
status: "error",
|
||||||
title: "Connection failed",
|
title: "Connection failed",
|
||||||
message: "Could not connect to given url"
|
message: "Could not connect to given url"
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user