Browse Source

webui: reauthenticate when token expires

pull/271/head
EinMByte 9 years ago
parent
commit
7e066f7f69
  1. 4
      webui/index.html
  2. 16
      webui/javascript/I2PControl.js

4
webui/index.html

@ -9,8 +9,8 @@ @@ -9,8 +9,8 @@
<script type="text/javascript">
function updateRouterInfo(result, session) {
if(session.error) {
alert("Error: " + result["error"]);
return; // TODO: try to recover
alert("Error: " + session.error["message"]);
return;
}
I2PControl.updateDocument({
"version" : result["i2p.router.version"],

16
webui/javascript/I2PControl.js

@ -16,11 +16,19 @@ I2PControl.Session.prototype = { @@ -16,11 +16,19 @@ I2PControl.Session.prototype = {
var self = this;
request.onreadystatechange = function() {
if(this.readyState == 4 && this.status == "200" && this.responseText != "") {
var result = JSON.parse(this.responseText).result;
if(result.hasOwnProperty("error")) {
self.error = true;
var data = JSON.parse(this.responseText);
if(data.hasOwnProperty("error")) {
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 != "")

Loading…
Cancel
Save