convertResponse<ResultType, Item> method
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
FutureOr<Response<ResultType>> convertResponse<ResultType, Item>(
Response response) async {
if (ResultType == NoContent) {
return response.copyWith<NoContent>(body: NoContent())
as Response<ResultType>;
}
// use [JsonConverter] to decode json
final jsonRes = await super.convertResponse(response);
return jsonRes.copyWith<ResultType>(body: _decode<Item>(jsonRes.body));
}