onResponse method

  1. @override
void onResponse(
  1. Response response,
  2. ResponseInterceptorHandler handler
)

Handles dio response and adds data to nirikshak http call

Implementation

@override
void onResponse(
  Response response,
  ResponseInterceptorHandler handler,
) {
  final httpResponse = NirikshakHttpResponse();
  httpResponse.status = response.statusCode ?? -1;
  httpResponse.statusMessage = response.statusMessage ?? 'N/A';

  if (response.data == null) {
    httpResponse.body = "";
    httpResponse.size = 0;
  } else {
    httpResponse.body = response.data;
    httpResponse.size = utf8.encode(response.data.toString()).length;
  }

  httpResponse.time = DateTime.now();
  Map<String, String> headers = {};
  response.headers.forEach((header, values) {
    headers[header] = values.toString();
  });

  httpResponse.headers = headers;

  nirikshakCore.addResponse(httpResponse, response.requestOptions.hashCode);
  return super.onResponse(response, handler);
}