private function parseResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
            throw new ClientErrorException($response);
        }

        if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
            throw new ServerErrorException($response);
        }

        $response->getBody()->rewind();

        $result = json_decode($response->getBody()->getContents());

        if ($result === null) {
            throw InvalidResponseException::failedToDecodeResponse($response, json_last_error_msg());
        }

        return $result;
    }