/**
  * Constructor.
  *
  * @param ResponseInterface $response The API response.
  */
 public function __construct(ResponseInterface $response)
 {
     $apiErrorResponse = new ApiErrorResponse();
     $apiErrorResponse->setStatus($response->getStatusCode());
     $apiErrorResponse->setMessage($response->getReasonPhrase());
     parent::__construct($apiErrorResponse);
 }
 /**
  * Create an ApiException from a client exception.
  *
  * @param ClientException $e The client exception.
  * @return ApiException
  * @throws \Speicher210\KontaktIO\Exception\ApiKeyInvalidException
  */
 protected function createApiException(ClientException $e)
 {
     $response = $e->getResponse();
     if (in_array($response->getStatusCode(), array(401, 403), true)) {
         throw new ApiKeyInvalidException($response);
     }
     if ($response->getBody()->getSize() > 0) {
         /** @var ApiErrorResponse $apiErrorResponse */
         $apiErrorResponse = $this->serializer->deserialize($e->getResponse()->getBody(), ApiErrorResponse::class, 'json');
     } else {
         $apiErrorResponse = new ApiErrorResponse();
         $apiErrorResponse->setStatus($response->getStatusCode());
         $apiErrorResponse->setMessage($response->getReasonPhrase());
     }
     return new ApiException($apiErrorResponse, $e);
 }