You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
728 B

const lib_errors = {
// Extract jqxhr error message
extractJqxhrErrorMsg: function(jqxhr) {
let hasErrorMsg = ('responseJSON' in jqxhr) &&
(jqxhr['responseJSON'] != null) &&
('error' in jqxhr['responseJSON']) &&
(typeof jqxhr['responseJSON']['error'] == 'string')
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)
}
},
}