Skip to content

Instantly share code, notes, and snippets.

@kendhia
Created September 3, 2020 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendhia/4f3b96b868f8413a472a1fe020b6421c to your computer and use it in GitHub Desktop.
Save kendhia/4f3b96b868f8413a472a1fe020b6421c to your computer and use it in GitHub Desktop.
restApi.interceptors.response.use(
async response => {
return response;
},
error => {
if (error.response && error.response.status === 401) {
console.log('401');
return renewUserToken(
username, password
).then(res => {
console.log('NEW TOKEN RECEIVED');
setRestToken(res.Token);
// resending the previous request again
error.config.headers['Access-Token'] = res.Token;
return axios.request(error.config);
});
}
return Promise.reject(error);
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment