I am using interceptor that refreshes the access token upon a status code of 401
but my catch
has stopped working upon any other error codes such as 400
request.js
import axios from 'axios'
const axiosApiInstance = axios.create()
axiosApiInstance.interceptors.response.use(
(response) => {
return response
},
(error) => {
return new Promise((resolve) => {
const originalRequest = error.config
const refreshToken = localStorage.getItem("refresh")
if (error.response && error.response.status === 401 && error.config && !error.config.__isRetryRequest && refreshToken) {
originalRequest._retry = true
const response = fetch('http://127.0.0.1:8000/api/token/refresh/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
refresh: refreshToken,
}),
})
.then((res) => res.json())
.then((res) => {
localStorage.setItem("access", res.access)
originalRequest.headers['Authorization'] = 'Bearer ' + res.access
return axios(originalRequest)
})
resolve(response)
}
return Promise.reject(error)
})
},
)
export default axiosApiInstance