WTokenInterceptor class
Token 拦截器,用于处理 token 的添加、更新和错误处理
功能包括:
- 在请求中自动添加 token
- 在响应中自动更新 token
- 处理未授权错误,清除 token
- 处理 token 过期情况
Constructors
-
WTokenInterceptor({Future<
String?> onAuthError()?, void onRequestOptions(RequestOptions)?, void onResponseOptions(Response)?, void onErrorOptions(DioException)?, int unauthorizedStatusCode = 401, int maxAuthRetries = 1}) - 构造函数
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxAuthRetries → int
-
认证错误最大重试次数
final
-
onAuthError
→ Future<
String?> Function()? -
认证错误处理回调,返回新的 token
final
- onErrorOptions → void Function(DioException)?
-
错误处理回调,用于在处理错误后修改错误
final
- onRequestOptions → void Function(RequestOptions)?
-
请求选项修改回调,用于在添加 token 前修改请求选项
final
- onResponseOptions → void Function(Response)?
-
响应处理回调,用于在处理响应后修改响应
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
未授权错误状态码,默认为 401
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
DioException err, ErrorInterceptorHandler handler) → Future< void> - Called when an exception was occurred during the request.
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void - Called when the request is about to be sent.
-
onResponse(
Response response, ResponseInterceptorHandler handler) → Future< void> - Called when the response is about to be resolved.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited