on401Unauthorized property

VoidCallback? on401Unauthorized
final

401 未授权回调(专门处理 401 错误)

包层面会自动对 401 进行去重处理,在 errorDeduplicationWindow 时间窗口内 只会调用一次此回调,避免并发请求时重复处理。

如果设置了此回调,401 错误将优先使用此回调,不再调用 onFailure

若同时配置了 unauthorizedRetry,且本次请求因刷新返回 false 已调用 UnauthorizedRetryConfig.onRefreshFailed,则不会再调用本回调(避免与 onRefreshFailed 重复跳转/提示)。

示例:

on401Unauthorized: () {
  AuthUtil.clearLoginInfo();
  Get.offAllNamed(Routes.LOGIN);
  Get.snackbar('提示', '登录已过期,请重新登录');
}

Implementation

final VoidCallback? on401Unauthorized;