dio
dio copied to clipboard
使用 QueuedInterceptorsWrapper 有问题
使用最新的 4.04 版本
在使用 QueuedInterceptorsWrapper 处理 onError 的 401 状态码,其中刷新 token 成功后使用 dio.fetch 再次请求时,当该请求失败后,则 onError 回调不会触发,造成上层调用方一直处于等待,无法响应,大致代码示例如下:
QueuedInterceptorsWrapper(
onError: (err, handler) {
if (err.response?.statusCode == 401) {
// 刷新 token
_refreshToken().then((resp) {
// process token code...
// token 刷新成功后,继续重发请求,当失败后 onError 不再回调,则上层调用方一直处于等待状态,无法响应
dio.fetch(err.requestOptions).then(
(value) => handler.resolve(value),
onError: (e) => handler.reject(e),
);
});
return;
}
handler.next(err);
},
);
之前继承 Interceptor 类并使用 lock 的方式没有任何问题,重新请求失败后会再次触发 onError 回调
the same situation
the same situation
I confirm this error
If google translator got you right, issue of not triggering onError callback is that queue interceptor is busy processing your current request and hence blocks any other requests like the one you make when you do dio.fetch. Solution is to use different dio instance when you do dio.fetch
dio.fetch 要使用新的dio实例
那这样的话 example 需要更新一下
Hi same issue for me, OnError is not triggered after a successful refresh token (not always). I will continue to use dio.lock() logic instead of QueuedInterceptorWrapper
not always but in some case we have facing similar issue. onRequest method of QueuedInterceptorsWrapper triggered but onError not.
the pr fix it: https://github.com/flutterchina/dio/pull/1457
使用最新的 4.04 版本
在使用 QueuedInterceptorsWrapper 处理 onError 的 401 状态码,其中刷新 token 成功后使用 dio.fetch 再次请求时,当该请求失败后,则 onError 回调不会触发,造成上层调用方一直处于等待,无法响应,大致代码示例如下:
QueuedInterceptorsWrapper( onError: (err, handler) { if (err.response?.statusCode == 401) { // 刷新 token _refreshToken().then((resp) { // process token code... // token 刷新成功后,继续重发请求,当失败后 onError 不再回调,则上层调用方一直处于等待状态,无法响应 dio.fetch(err.requestOptions).then( (value) => handler.resolve(value), onError: (e) => handler.reject(e), ); }); return; } handler.next(err); }, );之前继承 Interceptor 类并使用 lock 的方式没有任何问题,重新请求失败后会再次触发 onError 回调
请问解决了么
@AlexV525
@AlexV525
https://github.com/flutterchina/dio/issues/1339#issuecomment-1001400111
已经使用使用新的dio实例 但在refreshToken也过期后 需要跳转到登录 登录成功后 如果token再过期,onError 回调就不会触发,造成上层调用方一直处于等待
已经使用使用新的dio实例 但在refreshToken也过期后 需要跳转到登录 登录成功后 如果token再过期,onError 回调就不会触发,造成上层调用方一直处于等待
听起来跟 dio 没有任何关系,单纯的代码没写好。
已经使用使用新的dio实例 但在refreshToken也过期后 需要跳转到登录 登录成功后 如果token再过期,onError 回调就不会触发,造成上层调用方一直处于等待
听起来跟 dio 没有任何关系,单纯的代码没写好。
但是QueuedInterceptorsWrapper 中 onRequest 是可以监听到的 onError 就不触发了
我的 app 有完備的測試例 用 QueuedInterceptor 重寫了 Token 相關的代碼後 所有處理連續異常的場景的測試例都超時了
我的感覺是 QueuedInterceptor.onError 裡調用同一個 dio 實例會導致死鎖。
感覺是個設計缺陷: https://github.com/flutterchina/dio/issues/1612