jackwener/OpenCLI · error · AuthRequiredError

${authMessage}

Error message

${authMessage}

What it means

throwTikTokPageContextError maps raw page-scrape failures to typed errors. When the error message matches looksTikTokAuthFailure (login/session indicators), it rethrows as AuthRequiredError for tiktok.com using the caller-supplied authMessage.

Source

Thrown at clis/tiktok/utils.js:152

    return {
        url: parsed.toString(),
        username: match[1],
        videoId: match[2],
    };
}

export function looksTikTokAuthFailure(message) {
    return /\bAUTH_REQUIRED\b|\b(auth|captcha|login|log in|permission|unauthori[sz]ed|forbidden)\b|HTTP\s+(401|403)\b/i.test(String(message || ''));
}

export function looksTikTokUpstreamFailure(message) {
    return /\b(API failed|HTTP\s+\d+|invalid JSON|Failed to fetch|network|fetch)\b/i.test(String(message || ''));
}

export function throwTikTokPageContextError(error, { authMessage, emptyPattern, emptyTarget, failureMessage }) {
    const message = getErrorMessage(error);
    if (looksTikTokAuthFailure(message)) {
        throw new AuthRequiredError('tiktok.com', authMessage);
    }
    if (looksTikTokUpstreamFailure(message)) {
        throw new CommandExecutionError(`${failureMessage}: ${message}`);
    }
    if (emptyPattern.test(message)) {
        throw new EmptyResultError(emptyTarget, message);
    }
    throw new CommandExecutionError(`${failureMessage}: ${message}`);
}

// Sentinels emitted by Route 1 (button-walker) IIFEs and mapped here to
// typed errors. Keeping the strings constant in one place makes the IIFE
// `throw new Error(...)` callsites greppable and the mapper exhaustive.
export const BUTTON_WALKER_SENTINELS = {
    AUTH_REQUIRED: 'AUTH_REQUIRED',
    BUTTON_NOT_FOUND: 'BUTTON_NOT_FOUND',
    STATE_VERIFY_FAIL: 'STATE_VERIFY_FAIL',
    RATE_LIMITED: 'RATE_LIMITED',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-authenticate with tiktok.com (log in again / refresh the stored session) and retry
  2. Verify cookies/session state the CLI relies on are present and not expired
  3. Run a cheaper authenticated call first to confirm the session is valid
  4. If you believe you are logged in, check the raw upstream message for a login-wall false positive

Example fix

// before
await cli.listFollowing(); // throws AuthRequiredError after session expiry
// after
await cli.ensureTikTokLogin(); // re-establish session
await cli.listFollowing();
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify session freshness before listing calls
const ok = await page.evaluate(() => !document.body.innerText.includes('Log in'));

Type guard

const isAuthRequiredError = (e) => e instanceof AuthRequiredError || /auth|log in|login/i.test(e?.message ?? '');

Try / catch

try { await cli.listFollowing(); } catch (e) { if (e instanceof AuthRequiredError) { await reloginTikTok(); return cli.listFollowing(); } throw e; }

Prevention

When it happens

Trigger: A page-context listing call (listExploreVideos, listFollowing, listFriends, listLive, listNotifications, listUserVideos) fails and its message matches the auth-failure pattern — e.g. TikTok returned a login wall or 'not logged in' text.

Common situations: Expired or missing browser session/cookies; TikTok logged the automation account out; scraping from a datacenter IP triggering a login wall; stale saved session after a TikTok logout.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/eb8475baa18ecdf1. Report an issue: GitHub.