{"record":{"id":"6f619efb90b35da7","repo":"DIYgod/RSSHub","slug":"unsupported-region-code-region","errorCode":null,"errorMessage":"Unsupported region code: ${region}","messagePattern":"Unsupported region code: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/carousell/index.ts","lineNumber":261,"sourceCode":"            includeBpEducationBanner: true,\n            includeListingDescription: false,\n            includePopularLocations: false,\n            includeSuggestions: 'true',\n            isCertifiedSpotlightEnabled: false,\n            locale: 'zh-Hant-TW',\n            prefill: { prefill_sort_by: '3' },\n            // query: '',\n            sortParam: { fieldName: '3' },\n        },\n        referer: (query) => `https://tw.carousell.com/search/${query}?addRecent=true&canChangeKeyword=true&includeSuggestions=true&t-search_query_source=direct_search`,\n    },\n};\n\nasync function handler(ctx): Promise<Data> {\n    const { region, keyword } = ctx.req.param();\n\n    if (!Object.keys(regionMap).includes(region)) {\n        throw new Error(`Unsupported region code: ${region}`);\n    }\n\n    const baseUrl = regionMap[region].baseUrl;\n    const siteResponse = await ofetch.raw(baseUrl);\n    const cookies = siteResponse.headers\n        .getSetCookie()\n        ?.map((c) => c.split(';', 1)[0])\n        .join('; ');\n    const csrfToken = siteResponse._data.match(/\"csrfToken\":\"(.*?)\",\"/)[1];\n\n    const response = await ofetch(regionMap[region].api, {\n        method: 'POST',\n        headers: {\n            cookie: cookies,\n            'csrf-token': csrfToken,\n            referer: regionMap[region].referer(keyword),\n        },\n        body: {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/carousell/index.ts#L243-L279","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Use a 2-letter lowercase region code from the supported list: au, ca, hk, id, my, nz, ph, sg, tw.","Maintainers: switch to `InvalidParameterError` and prefer `region in regionMap` / `regionMap.hasOwnProperty(region)` over `Object.keys().includes()`."],"exampleFix":"// before\n/carousell/australia/iphone\n// after\n/carousell/au/iphone","handlingStrategy":"validation","validationCode":"const REGIONS = ['au','ca','hk','id','my','nz','ph','sg','tw'] as const;\nif (!(REGIONS as readonly string[]).includes(region)) {\n    throw new Error(`Unsupported region '${region}'. Use one of: ${REGIONS.join(', ')}`);\n}","typeGuard":"const REGIONS = ['au','ca','hk','id','my','nz','ph','sg','tw'] as const;\ntype CarousellRegion = typeof REGIONS[number];\nfunction isCarousellRegion(v: string): v is CarousellRegion {\n    return (REGIONS as readonly string[]).includes(v);\n}","tryCatchPattern":null,"preventionTips":["Use the 2-letter lowercase ISO code, never the country name or ISO-3.","Maintainers: prefer `region in regionMap` over `Object.keys().includes()`; throw `InvalidParameterError`."],"tags":["validation","user-input","route-parameter","lookup-table"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}