onResponse method

  1. @override
void onResponse(
  1. Response response,
  2. ResponseInterceptorHandler handler
)
override

Called when the response is about to be resolved.

Implementation

@override
void onResponse(response, handler) async {
  OnResponseHandler? onResponseHandler = HttpService.to.onResponseHandler;
  if (onResponseHandler != null) {
    String? msg = await onResponseHandler(response);
    if (msg != null) {
      handler.reject(
        DioException(
          type: DioExceptionType.badResponse,
          message: msg.isEmpty ? '服务器异常' : msg,
          requestOptions: response.requestOptions,
          response: response,
          error: null,
        ),
      );
      return;
    }
  }
  handler.next(response);
}