handleResponse<T> function

HttpResponse<T> handleResponse<T>(
  1. Response? response, {
  2. HttpTransformer? httpTransformer,
})

Implementation

HttpResponse<T> handleResponse<T>(Response? response,
    {HttpTransformer? httpTransformer}) {

  // 返回值异常
  if (response == null) {
    return HttpResponse.failureFromError();
  }

  // token失效
  if (_isTokenTimeout(response.statusCode)) {
    return HttpResponse.failureFromError(
        UnauthorisedException(message: "没有权限", code: response.statusCode.toString()));
  }
  // 接口调用成功
  if (_isRequestSuccess(response.statusCode)) {
    return httpTransformer!.parse<T>(response);
  } else {
    // 接口调用失败
    return HttpResponse.failure(
        errorMsg: response.statusMessage, errorCode: '${response.statusCode}');
  }
}