Created
April 24, 2017 16:35
-
-
Save alexanderzobnin/afe55d2376300d07985b69f4374fec42 to your computer and use it in GitHub Desktop.
Zabbix API JS login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request(method, params) { | |
return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth) | |
.catch(error => { | |
if (isNotAuthorized(error.data)) { | |
// Handle auth errors | |
this.loginErrorCount++; | |
if (this.loginErrorCount > this.maxLoginAttempts) { | |
this.loginErrorCount = 0; | |
return null; | |
} else { | |
return this.loginOnce() | |
.then(() => this.request(method, params)); | |
} | |
} else { | |
// Handle API errors | |
let message = error.data ? error.data : error.statusText; | |
this.alertAPIError(message); | |
} | |
}); | |
} | |
function isNotAuthorized(message) { | |
return ( | |
message === "Session terminated, re-login, please." || | |
message === "Not authorised." || | |
message === "Not authorized." | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment