assureResponse<T> static method

  1. @internal
Response<T> assureResponse<T>(
  1. Object response,
  2. RequestOptions requestOptions
)

Implementation

@internal
static Response<T> assureResponse<T>(
  Object response,
  RequestOptions requestOptions,
) {
  if (response is! Response) {
    return Response<T>(
      data: response as T,
      requestOptions: requestOptions,
    );
  } else if (response is! Response<T>) {
    final T? data = response.data as T?;
    final Headers headers;
    if (data is ResponseBody) {
      headers = Headers.fromMap(
        data.headers,
        preserveHeaderCase: requestOptions.preserveHeaderCase,
      );
    } else {
      headers = response.headers;
    }
    return Response<T>(
      data: data,
      headers: headers,
      requestOptions: response.requestOptions,
      statusCode: response.statusCode,
      isRedirect: response.isRedirect,
      redirects: response.redirects,
      statusMessage: response.statusMessage,
      extra: response.extra,
    );
  }
  return response;
}