[lib.api-client] automatic logout when invalid authentication

This commit is contained in:
xdrm-brackets 2018-04-04 16:13:34 +02:00
parent 1d6ec8c5d1
commit 5e5fff8545
1 changed files with 9 additions and 2 deletions

View File

@ -53,14 +53,21 @@ export default class APIClient{
this.received = true;
/* Try to parse JSON */
try{ _response = JSON.parse(_response); }catch(e){ _callback({error: -1}); }
try{ _response = JSON.parse(_response); }catch(e){ _callback({error: -2}); }
/* If authentication failed -> logout user*/
if( typeof _response.error === 'number' && _response.error === -1 ){
auth.token = null;
document.location = '';
return;
}
/* Launch @_callback with response */
_callback(_response);
}.bind(persist);
this.xhr_driver.onclose = function(){ !this.received && _callback({ error: -2 }); }.bind(persist);
this.xhr_driver.onclose = function(){ !this.received && _callback({ error: -3 }); }.bind(persist);
return this.xhr_driver.send({