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 = '';
    if (response.bodyBytes != null) {
      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;
  }
}