protected function evaluateResponse(array $response) {
        if (array_key_exists('error', $response) &&
            $response['error'] !== null) {
            // Validate error object:
            if (!is_array($response['error'])) {
                throw new RuntimeException('Invalid error object');
            }

            if (!array_key_exists('code', $response['error']) ||
                !is_int($response['error']['code']) ||
                $response['error']['code'] >= 0) {
                throw new RuntimeException('Invalid error code');
            }

            if (!array_key_exists('message', $response['error']) ||
                !is_string($response['error']['message']) ||
                strlen($response['error']['message']) === 0) {
                throw new RuntimeException('Invalid error message');
            }

            $details = [];

            if (array_key_exists('data', $response['error']) &&
                is_array($response['error']['data'])) {
                foreach ($response['error']['data'] as $topic => $description) {
                    $text = 'unknown';

                    switch (gettype($description)) {
                        case 'array':
                            $text = implode('; ', $description);
                            break;
                        case 'string':
                            $text = $description;
                            break;
                    }

                    $details[] = sprintf(
                        '%s: %s',
                        $topic,
                        $text
                    );
                }
            }

            if (count($details) > 0) {
                $message = sprintf(
                    'i-doit responded with an error: %s [%s]',
                    $response['error']['message'],
                    implode('; ', $details)
                );
            } else {
                $message = sprintf(
                    'i-doit responded with an error: %s',
                    $response['error']['message']
                );
            }

            throw new RuntimeException(
                $message,
                $response['error']['code']
            );
        }

        if (!array_key_exists('result', $response)) {
            throw new RuntimeException('i-doit forgot to add a result to its response.');
        }

        return $this;
    }