private function validateResponse($response) {
        if ($response->getStatusCode() !== 200) {
            $statusCode = $response->getStatusCode();
            throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
        } else if (strpos($response->getHeader('Content-Type')[0], 'application/json') === false) {
            throw new ServerException('Server did not respond with the expected content-type (application/json)');
        }

        try {
            $body = (string) $response->getBody();
            $json = json_decode($body, true);
            if (json_last_error()) {
                throw new ServerException(json_last_error_msg());
            }
        } catch (RuntimeException $e) {
            throw new ServerException($e->getMessage());
        }
    }