DIYgod/RSSHub · error · Error

api error

Error message

api error

What it means

Generic Error thrown inside doGot when the response body is a string (i.e. an HTML challenge page, not the expected JSON) but the regex /document\.cookie\s*=\s*"([^"]*)"/ finds no match. It means the server returned an HTML page whose cookie-setting syntax the helper cannot parse, so it cannot proceed with the challenge.

Source

Thrown at lib/routes/bt0/util.ts:19

import { CookieJar } from 'tough-cookie';

import got from '@/utils/got';

const cookieJar = new CookieJar();

async function doGot(num, host, link) {
    if (num > 4) {
        throw new Error('The number of attempts has exceeded 5 times');
    }
    const response = await got.get(link, {
        cookieJar,
    });
    const data = response.data;
    if (typeof data === 'string') {
        const regex = /document\.cookie\s*=\s*"([^"]*)"/;
        const match = data.match(regex);
        if (!match) {
            throw new Error('api error');
        }
        cookieJar.setCookieSync(match[1], host);
        return doGot(num + 1, host, link);
    }
    return data;
}

const genSize = (sizeStr) => {
    // 正则表达式,用于匹配数字和单位 GB 或 MB
    const regex = /^(\d+(\.\d+)?)\s*(gb|mb)$/i;
    const match = sizeStr.match(regex);

    if (!match) {
        return 0;
    }

    const value = Number(match[1]);
    const unit = match[3].toUpperCase();

View on GitHub (pinned to bed535e087)

Solutions

  1. Fetch the same URL with curl/the helper's cookieJar and inspect the HTML to see how the cookie is now set; update the regex accordingly.
  2. If the page is a captcha/hard block, the IP is likely banned — route through a different egress or retry later.
  3. Confirm the endpoint URL (_link in mv.ts/tlist.ts) still returns the challenge and not a 404.

Example fix

// before
if (!match) {
    throw new Error('api error');
}
// after (include a snippet for diagnosis)
if (!match) {
    throw new Error(`bt0 api error: HTML challenge has no document.cookie match (first 200 chars: ${data.slice(0, 200)})`);
}
Defensive patterns

Strategy: retry

Validate before calling

if (typeof data === 'string') {
    const match = data.match(/document\.cookie\s*=\s*"([^"]*)"/);
    if (!match) throw new Error(`bt0 api error: no document.cookie match in HTML (len ${data.length})`);
    cookieJar.setCookieSync(match[1], host);
    return doGot(num + 1, host, link);
}

Type guard

const isCookieChallengeHtml = (s: string): boolean =>
    /document\.cookie\s*=\s*"[^"]*"/.test(s);

Try / catch

// If the regex misses once, retry the raw fetch — the challenge page can be intermittent:
let body = await got.get(link, { cookieJar });
if (typeof body.data === 'string' && !isCookieChallengeHtml(body.data)) {
    // one fresh attempt before failing
    body = await got.get(link, { cookieJar });
}

Prevention

When it happens

Trigger: response.data is a string (HTML) but contains no `document.cookie="..."` assignment — e.g. the anti-bot page changed to set cookies via a function call, a meta tag, or no cookie at all (a hard block / maintenance page).

Common situations: bt0 updated its anti-bot template; the page is a hard 403/captcha instead of a JS cookie challenge; an intermediate proxy rewrote the HTML.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/719a7d00080b4068. Report an issue: GitHub.