private function checkError(ResponseInterface $response, $url)
    {
        if (($response->getStatusCode() == 200) || ($response->getStatusCode() == 201)) {
            return;
        }

        switch ($response->getHeader('Content-Type')) {
            case 'text/plain':
                throw new \RuntimeException('Error: ' . $response->getBody() . ' URI: ' . $url);
            case 'application/json':
                $error = json_decode($response->getBody());
                if (isset($error->message)) {
                    throw new \RuntimeException($error->message . ' URI: ' . $url);
                }
                break;
            default:
                throw new \RuntimeException(
                    'Unknown Error: No error message was returned from the server - Code: ' . $response->getStatusCode(
                    ) . ' URI: ' . $url
                );
        }
    }