DIYgod/RSSHub · warning · Error

Unsupported region code: ${region}

Error message

Unsupported region code: ${region}

What it means

Thrown by the Carousell keyword-search route when the `region` path parameter is not a key in `regionMap`. Supported regions: au, ca, hk, id, my, nz, ph, sg, tw (verified from the route's `parameters.region.options`). Uses a plain `Error` instead of `InvalidParameterError`, and uses `Object.keys(regionMap).includes(region)` (O(n)) rather than a `has()` check.

Source

Thrown at lib/routes/carousell/index.ts:261

            includeBpEducationBanner: true,
            includeListingDescription: false,
            includePopularLocations: false,
            includeSuggestions: 'true',
            isCertifiedSpotlightEnabled: false,
            locale: 'zh-Hant-TW',
            prefill: { prefill_sort_by: '3' },
            // query: '',
            sortParam: { fieldName: '3' },
        },
        referer: (query) => `https://tw.carousell.com/search/${query}?addRecent=true&canChangeKeyword=true&includeSuggestions=true&t-search_query_source=direct_search`,
    },
};

async function handler(ctx): Promise<Data> {
    const { region, keyword } = ctx.req.param();

    if (!Object.keys(regionMap).includes(region)) {
        throw new Error(`Unsupported region code: ${region}`);
    }

    const baseUrl = regionMap[region].baseUrl;
    const siteResponse = await ofetch.raw(baseUrl);
    const cookies = siteResponse.headers
        .getSetCookie()
        ?.map((c) => c.split(';', 1)[0])
        .join('; ');
    const csrfToken = siteResponse._data.match(/"csrfToken":"(.*?)","/)[1];

    const response = await ofetch(regionMap[region].api, {
        method: 'POST',
        headers: {
            cookie: cookies,
            'csrf-token': csrfToken,
            referer: regionMap[region].referer(keyword),
        },
        body: {

View on GitHub (pinned to bed535e087)

Solutions

  1. Use a 2-letter lowercase region code from the supported list: au, ca, hk, id, my, nz, ph, sg, tw.
  2. Maintainers: switch to `InvalidParameterError` and prefer `region in regionMap` / `regionMap.hasOwnProperty(region)` over `Object.keys().includes()`.

Example fix

// before
/carousell/australia/iphone
// after
/carousell/au/iphone
Defensive patterns

Strategy: validation

Validate before calling

const REGIONS = ['au','ca','hk','id','my','nz','ph','sg','tw'] as const;
if (!(REGIONS as readonly string[]).includes(region)) {
    throw new Error(`Unsupported region '${region}'. Use one of: ${REGIONS.join(', ')}`);
}

Type guard

const REGIONS = ['au','ca','hk','id','my','nz','ph','sg','tw'] as const;
type CarousellRegion = typeof REGIONS[number];
function isCarousellRegion(v: string): v is CarousellRegion {
    return (REGIONS as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Calling `/carousell/<region>/<keyword>` with region not in {au, ca, hk, id, my, nz, ph, sg, tw}. Fails on uppercase (AU), full names (australia), or unsupported regions (us, uk).

Common situations: User supplies a country name or ISO-3 code instead of the 2-letter lowercase code; uses 'uk' expecting United Kingdom (Carousell has no UK instance).

Related errors


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