@fjedi/zabbix-client
Version:
Zabbix Javascript API Client
34 lines (33 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZabbixCommunicator = void 0;
const ZabbixResponseException_1 = require("./ZabbixResponseException");
class ZabbixCommunicator {
socket;
method;
constructor(socket, method) {
this.socket = socket;
this.method = method;
}
async call(params, noAuth) {
let response = {};
try {
response = await this.socket.call(this.method, params, noAuth);
}
catch (error) {
throw new ZabbixResponseException_1.ZabbixResponseException(error.message, response.config);
}
if (!response.data) {
throw new ZabbixResponseException_1.ZabbixResponseException({
data: response.statusText,
message: response.statusText,
code: response.status
}, response.config);
}
if (response.data && response.data.error) {
throw new ZabbixResponseException_1.ZabbixResponseException(response.data.error, response.config);
}
return response.data.result;
}
}
exports.ZabbixCommunicator = ZabbixCommunicator;