mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-13 04:46:38 +01:00
webui: reauthenticate when token expires
This commit is contained in:
parent
30798f835e
commit
7e066f7f69
2 changed files with 14 additions and 6 deletions
|
@ -9,8 +9,8 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function updateRouterInfo(result, session) {
|
function updateRouterInfo(result, session) {
|
||||||
if(session.error) {
|
if(session.error) {
|
||||||
alert("Error: " + result["error"]);
|
alert("Error: " + session.error["message"]);
|
||||||
return; // TODO: try to recover
|
return;
|
||||||
}
|
}
|
||||||
I2PControl.updateDocument({
|
I2PControl.updateDocument({
|
||||||
"version" : result["i2p.router.version"],
|
"version" : result["i2p.router.version"],
|
||||||
|
|
|
@ -16,11 +16,19 @@ I2PControl.Session.prototype = {
|
||||||
var self = this;
|
var self = this;
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if(this.readyState == 4 && this.status == "200" && this.responseText != "") {
|
if(this.readyState == 4 && this.status == "200" && this.responseText != "") {
|
||||||
var result = JSON.parse(this.responseText).result;
|
var data = JSON.parse(this.responseText);
|
||||||
if(result.hasOwnProperty("error")) {
|
if(data.hasOwnProperty("error")) {
|
||||||
self.error = true;
|
if(data["error"]["code"] == -32003 || data["error"]["code"] == -32004) {
|
||||||
|
// Get a new token and resend the request
|
||||||
|
self.start(function() {
|
||||||
|
self.request(method, params, handler);
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
handler(result, self);
|
// Cannot fix the error, report it
|
||||||
|
self.error = data["error"];
|
||||||
|
}
|
||||||
|
handler(data.result, self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if(this.token != "")
|
if(this.token != "")
|
||||||
|
|
Loading…
Add table
Reference in a new issue