Comments (6)
I'm not exactly sure what you're trying to achieve. Would you please edit your question with a code sample?
Manual ejection should be as simple as calling the following...
const refreshAuthIterceptorId = createAuthRefreshInterceptor(/* ... */);
axios.interceptors.response.eject(refreshAuthIterceptorId);
from axios-auth-refresh.
Well, if you emit it manually, you woudn't really need that library. But there's a bit more logic for it to work properly, as you need a queue for requests that has been dispatched while the token is refreshing, etc.
I think it might work if you move the createAuthRefreshInterceptor
above the onError
(so it gets called after your own $axios.onError
interceptor and instead of returning Promise.reject({ error: errorObject, data: errorObject.response.data })
you'd return the Promise.reject(errorObject);
. Can you try that?
createAuthRefreshInterceptor(/* ... */);
$axios.onError(async errorObject => {
const code = parseInt(errorObject.response && errorObject.response.status);
let message = '';
if (code === 404) {
message = 'Page not found';
}
if (code === 401) {
return Promise.reject(errorObject);
}
error({ statusCode: code, message });
return Promise.reject({
error: errorObject,
data: errorObject.response.data,
});
});
from axios-auth-refresh.
Well I think that in order to propagate the failed response to another interceptor you need to use Promise.reject(/* ... */)
not just a simple return, otherwise the error is treated as handled.
So in your example...
$axios.onError(async errorObject => {
const code = parseInt(errorObject.response && errorObject.response.status);
let message = '';
if (code === 404) {
message = 'Page not found';
}
if (code === 422) {
return Promise.reject({ error: errorObject, data: errorObject.response.data });
}
... // other codes
error({ statusCode: code, message });
return Promise.reject({ error: errorObject, data: errorObject.response.data });
});
Also, there might be a problem with the order in which the response interceptors are running, if that's the case, try putting the createAuthRefreshInterceptor
above the $axios.onError
(I'm not sure about that, just found the old thread for this one: axios/axios#1226)
from axios-auth-refresh.
Unfortunately, it didn't help. If I insert the createAuthRefreshInterceptor
above onError
handler with Promise.reject
, it is working the same.
But if I insert it below, it will reproduce the error in browser:
And no refresh request will sending
from axios-auth-refresh.
Maybe I can emit the handler for refresh mannually? Like:
$axios.onError(async errorObject => {
const code = parseInt(errorObject.response && errorObject.response.status);
let message = '';
if (code === 404) {
message = 'Page not found';
}
if (code === 401) {
startAuthRefresh(errorObject);
}
error({ statusCode: code, message });
return Promise.reject({
error: errorObject,
data: errorObject.response.data,
});
});
from axios-auth-refresh.
Thank you very much! It worked.
from axios-auth-refresh.
Related Issues (20)
- response.use will enter twice when retry HOT 2
- Implementation example HOT 1
- onRetry never firing HOT 5
- How to handle a 401 "Refresh token is invalid" error HOT 2
- Request is not being re-triggered after re-auth HOT 2
- Document whether all interceptors are rerun after refresh HOT 1
- Each call is getting duplicated HOT 1
- Interceptors fail to assign new token on second failure HOT 2
- Docs: Provide example for server-side axios requests nuxt HOT 1
- multiple axios instance. don't need to reqeuest refresh api multiple times
- Retry of the original request fails only if GET request HOT 4
- Axios auth refresh doesn't work with axios v1.1.3 HOT 7
- Resend request with multipart/formdata
- async shouldRefresh
- combine refresh token logic with another axios response interceptor
- Multiple Request Pause is not working HOT 2
- import('axios-auth-refresh') wraped with default HOT 2
- Problem using axios-auth-refresh with react-query HOT 2
- React Native 0.72.1 ? HOT 1
- 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-auth-refresh.