Open mzzsfy opened 1 year ago
之后可能会迁移到 fetch API,迁移之后再做考虑(我也不知道 fetch 有没有 interceptor 对应的实现)
In paticular your case, I think you could just catch
the exception and then resolve the re-login process.
try {
const res = ctx.http.get(url)
// ...
} catch (e) {
if (Quester.isAxiosError(e) {
if (e.statusCode === 401) {
// re-login and re-request
}
}
}
Well, there're no RAII or something in JS, the code might be ugly but usable for now.
我倾向于在目前的实现上直接提供一套api来做。因为其实并不需要使用axios的interceptor,只需要我们wrap一些东西
In paticular your case, I think you could just
catch
the exception and then resolve the re-login process.try { const res = ctx.http.get(url) // ... } catch (e) { if (Quester.isAxiosError(e) { if (e.statusCode === 401) { // re-login and re-request } } }
Well, there're no RAII or something in JS, the code might be ugly but usable for now.
目前我也是这样实现的,但这开发起来很不友好
请问能提供一些使用 axios interceptor 的示例代码吗?我有意实现相关的功能,不过想深入了解你的需求。
请问能提供一些使用 axios interceptor 的示例代码吗?我有意实现相关的功能,不过想深入了解你的需求。
我尝试在github上搜索了一些刷新token的例子: https://github.com/chengpeiquan/refresh-token/blob/27bfcbbfd531d99777a5cec003ac47adc4326447/src/libs/axios/index.ts
Describe the problem related to the feature request
检查到特定返回值自动重新登陆,
Describe the solution you'd like
ctx.http需要暴露interceptors或者提供拦截器功能
Describe alternatives you've considered
创建新的http
Additional context
No response