returnResponseOrThrowException function

Response returnResponseOrThrowException(
  1. Response response
)

Implementation

http.Response returnResponseOrThrowException(http.Response response) {
  if (response.statusCode == 404) {
    // Not found
    throw ItemNotFoundException(response.body);
  } else if (response.statusCode == 500) {
    throw InternalServerErrorException(response.body);
  } else if (response.statusCode == 400) {
    String responseBody = response.body;
    throw BadRequestException(responseBody);
  } else if (response.statusCode == 409) {
    throw ConflictErrorException(response.body);
  } else if (response.statusCode > 400) {
    throw UnknownApiException(response.statusCode);
  } else {
    return response;
  }
}