13 changed files with 57 additions and 45 deletions
@ -0,0 +1,24 @@ |
|||||
|
const lib_errors = { |
||||
|
|
||||
|
// Extract jqxhr error message
|
||||
|
extractJqxhrErrorMsg: function(jqxhr) { |
||||
|
let hasErrorMsg = ('responseJSON' in jqxhr) && |
||||
|
(jqxhr['responseJSON'] != null) && |
||||
|
('error' in jqxhr['responseJSON']) |
||||
|
|
||||
|
return hasErrorMsg ? jqxhr['responseJSON']['error'] : jqxhr.statusText |
||||
|
}, |
||||
|
|
||||
|
// Manage errors
|
||||
|
processError: function(e) { |
||||
|
const errorMsg = this.extractJqxhrErrorMsg(e) |
||||
|
// Redirect to sign in page if authentication error
|
||||
|
if (errorMsg == 'Invalid JSON Web Token' || errorMsg == 'Missing JSON Web Token') { |
||||
|
lib_auth.logout() |
||||
|
} else { |
||||
|
lib_msg.displayErrors(errorMsg) |
||||
|
console.log(e) |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
} |
Loading…
Reference in new issue