DIYgod/RSSHub · error · ConfigNotFoundError

Lofter 用户登录后的 Cookie 值

Error message

Lofter 用户登录后的 Cookie 值

What it means

Thrown by the Lofter tag handler (lib/routes/lofter/tag.ts:56) as a `ConfigNotFoundError` when `config.lofter.cookies` is `undefined`. The Lofter tag search DWR endpoint requires an authenticated session cookie to return results, so the route refuses to run without it.

Source

Thrown at lib/routes/lofter/tag.ts:56

| new  | date | week | month | total |
| ---- | ---- | ---- | ----- | ----- |
| 最新 | 日榜 | 周榜 | 月榜  | 总榜  |`,
};

async function handler(ctx) {
    const name = ctx.req.param('name') ?? '摄影';
    const type = ctx.req.param('type') ?? 'new';
    const pageSize = 20;
    const startingIndex = 0;

    const rootUrl = 'https://www.lofter.com';
    const linkUrl = `${rootUrl}/tag/${name}/${type}`;
    const apiUrl = `${rootUrl}/dwr/call/plaincall/TagBean.search.dwr`;

    const cookie = config.lofter.cookies;
    if (cookie === undefined) {
        throw new ConfigNotFoundError('Lofter 用户登录后的 Cookie 值');
    }

    const response = await got({
        method: 'post',
        url: apiUrl,
        body: new URLSearchParams({
            callCount: '1',
            scriptSessionId: '${scriptSessionId}187',
            httpSessionId: '',
            'c0-scriptName': 'TagBean',
            'c0-methodName': 'search',
            'c0-id': '0',
            'c0-param0': `string:${encodeURI(name)}`,
            'c0-param1': 'number:0',
            'c0-param2': 'string:',
            'c0-param3': `string:${type}`,
            'c0-param4': 'boolean:false',
            'c0-param5': 'number:0',

View on GitHub (pinned to bed535e087)

Solutions

  1. Set `LOFTER_COOKES=<cookie string>` in the RSSHub environment and restart.
  2. Copy the full `Cookie` header from a logged-in lofter.com browser session.
  3. Confirm the config schema exposes it as `config.lofter.cookies`.

Example fix

// before: env unset
LOFTER_COOKIES=

// after
LOFTER_COOKIES=userNames=...; __utmz=...; LOFTER_PERSISTENT=...
Defensive patterns

Strategy: validation

Validate before calling

function lofterCookiesConfigured(): boolean {
    return typeof config.lofter?.cookies === 'string' && config.lofter.cookies.length > 0;
}
if (!lofterCookiesConfigured()) {
    throw new Error('Set LOFTER_COOKIES before enabling Lofter tag routes');
}

Type guard

function hasLofterCookies(c: typeof config): c is typeof config & { lofter: { cookies: string } } {
    return typeof c.lofter?.cookies === 'string' && c.lofter.cookies.length > 0;
}

Try / catch

import ConfigNotFoundError from '@/errors/types/config-not-found';
try {
    await fetchLofterTag(name, type);
} catch (e) {
    if (e instanceof ConfigNotFoundError && /Cookie/.test(e.message)) {
        return { disabled: true, reason: 'LOFTER_COOKIES env var not set' };
    }
    throw e;
}

Prevention

When it happens

Trigger: Deploying RSSHub without `LOFTER_COOKIES` configured; setting it to an empty string; config key misspelled so `config.lofter.cookies` is undefined.

Common situations: Fresh install omitting route-specific config; cookie value expired and was cleared; config not reloaded after edit.

Related errors


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