convertResponse<ResultType, Item> method

  1. @override
Response<ResultType> convertResponse<ResultType, Item>(
  1. Response response
)

Converts the received Response to a Response which has a body of the type BodyType.

BodyType is the expected type of the resulting Response's body (e.g., String or CustomObject).

If BodyType is a List or a BuiltList, InnerType is the type of the generic parameter (e.g., convertResponse<List<CustomObject>, CustomObject>(response) ).

Implementation

@override
chopper.Response<ResultType> convertResponse<ResultType, Item>(
    chopper.Response response) {
  if (response.bodyString.isEmpty) {
    // In rare cases, when let's say 204 (no content) is returned -
    // we cannot decode the missing json with the result type specified
    return chopper.Response(response.base, null, error: response.error);
  }

  final jsonRes = super.convertResponse(response);
  return jsonRes.copyWith<ResultType>(
      body: jsonDecoder.decode<Item>(jsonRes.body) as ResultType);
}