diff --git a/webpack/lib/api-client.js b/webpack/lib/api-client.js index 848e3bf..b1e8aa1 100644 --- a/webpack/lib/api-client.js +++ b/webpack/lib/api-client.js @@ -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({