diff --git a/lib/core/network/dio_client.dart b/lib/core/network/dio_client.dart index 6906010f..76b9f2e1 100644 --- a/lib/core/network/dio_client.dart +++ b/lib/core/network/dio_client.dart @@ -40,12 +40,17 @@ class DioClient { if (response.data is Map) { final code = response.data['code']; if (code == 401 || code == 403) { - print( - '>>> [DIO] 🚨🚨🚨 收到业务错误码 $code,触发 Token 过期处理!URL: ${response.requestOptions.uri},时间: ${DateTime.now()}', - ); - try { - sl().tokenExpired(); - } catch (ex) {} + // 🔥 仅在当前确实处于登录态时,才把 401 当作「登录过期」弹窗。 + // 退出登录过程中 AppUserCubit.user 已被清为 null,此时残留/竞态请求 + // 返回的 401 不应再打扰用户(人已经在退出了),否则会误弹「登录已过期」。 + if (sl().state.user != null) { + print( + '>>> [DIO] 🚨🚨🚨 收到业务错误码 $code,触发 Token 过期处理!URL: ${response.requestOptions.uri},时间: ${DateTime.now()}', + ); + try { + sl().tokenExpired(); + } catch (ex) {} + } } } return handler.next(response); @@ -53,12 +58,15 @@ class DioClient { onError: (DioException e, handler) async { if (e.response?.statusCode == 401 || e.response?.statusCode == 403) { - print( - '>>> [DIO] 🚨🚨🚨 收到 HTTP ${e.response?.statusCode},触发 Token 过期处理!URL: ${e.requestOptions.uri},时间: ${DateTime.now()}', - ); - try { - sl().tokenExpired(); - } catch (ex) {} + // 🔥 同上:已退出登录(user==null)时不再触发过期弹窗 + if (sl().state.user != null) { + print( + '>>> [DIO] 🚨🚨🚨 收到 HTTP ${e.response?.statusCode},触发 Token 过期处理!URL: ${e.requestOptions.uri},时间: ${DateTime.now()}', + ); + try { + sl().tokenExpired(); + } catch (ex) {} + } } return handler.next(e);