public function solve(string $challengeUrl) : string
    {
        $result = $this->createTask($challengeUrl);

        if ($result['errorId'] !== 0) {
            $this->getLogger()->error(
                "Received AntiCaptcha ErrorId: {ErrorId}: {ErrorDescription}",
                [
                    'ErrorId'          => $result['errorId'],
                    'ErrorDescription' => $result['errorDescription']
                ]
            );

            if ($result['errorId'] == 1) {
                throw new InvalidKeyException();
            }

            if ($result['errorId'] == 10) {
                throw new BalanceTooLowException();
            }

            throw new RemoteSolverException(sprintf("AntiCaptcha error: %s: %s", $result['errorId'], $result['errorDescription']));
        }

        $this->getLogger()->debug("Task successfully created for challenge {Challenge}", ['Challenge' => $challengeUrl]);

        $taskId = $result['taskId'];

        $start = time();

        while (true) {
            if (time() - $start > $this->timeout) {
                throw new TimeoutException("AntiCaptcha waiting for result timed out after " . $this->timeout . " seconds.");
            }

            $result = $this->checkResult($taskId);

            if ($result === true) {
                sleep($this->interval);
                continue;
            }

            if ($result === false) {
                throw new RemoteSolverException("Remote error.");
            }

            return $result;
        }

        return false;
    }