protected function verifyResponse(Response $response)
    {
        $content = json_decode($response->getContent(), true);
        $statusCode = $response->getStatusCode();

        if ($statusCode !== 204 && null === $content) {
            throw new LibraryException('Unable to parse response from server (status code: '.$response->getStatusCode().') '.$response->getContent());
        }

        if (isset($content['status']) && $content['status'] !== ExceptionFactory::STATUS_SUCCESS) {
            throw ExceptionFactory::createExceptionFromArray($content);
        }

        if ($statusCode !== 200 && $statusCode !== 204 && ($statusCode < 300 || $statusCode > 303)) {
            throw new LibraryException(sprintf('Invalid status code (expected 200, 204, or 300-303. Got %s). Response content: %s', $statusCode, $response->getContent()));
        }
    }