onConvertResponse method

  1. @protected
FutureOr<StreamedResponse> onConvertResponse(
  1. StreamedResponse response
)

Implementation

@protected
FutureOr<StreamedResponse> onConvertResponse(
  StreamedResponse response,
) async {
  final responseConverters = this.responseConverters;
  if (responseConverters == null || responseConverters.isEmpty) {
    return response;
  }

  StreamedResponse modifiedResponse = response;

  for (final converter in responseConverters) {
    try {
      modifiedResponse = await converter(modifiedResponse);
    } catch (e, s) {
      unawaitedResponse(response);
      throw ResponseConverterException(
        'Response Converter failed due to an error',
        uri: response.request?.url,
        innerException: e,
        innerStackTrace: s,
      );
    }
  }

  if (response != modifiedResponse) {
    unawaitedResponse(response);
  }

  return modifiedResponse;
}