handleResponse<T> method

dynamic handleResponse<T>(
  1. Response response, {
  2. dynamic handleSuccess(
    1. Response response
    )?,
})

Handles an API network response from Dio. handleSuccess overrides the return value handleFailure is called then the response status is not 200. You can return a different value using this callback.

Implementation

handleResponse<T>(Response response,
    {Function(Response response)? handleSuccess}) {
  bool wasSuccessful = response.statusCode == 200;

  if (wasSuccessful == true && handleSuccess != null) {
    return handleSuccess(response);
  }

  if (T.toString() != 'dynamic') {
    return _morphJsonResponse<T>(response.data);
  } else {
    return response.data;
  }
}