onFailure method
失败时执行回调 返回自身,支持链式调用 注意:如果调用了此方法,错误将被标记为已处理,全局的 onFailure 不会再被调用
回调参数:
- httpStatusCode HTTP 状态码(如 200, 404, 500 等,可能为 null)
- errorCode 业务错误码(可能为 null)
message错误消息
Implementation
Response<T> onFailure(
void Function(int? httpStatusCode, int? errorCode, String message)
callback) {
if (!isSuccess && errorMessage != null) {
callback(httpStatusCode, errorCode, errorMessage!);
_markErrorHandled(); // 标记错误已处理
}
return this;
}