{"record":{"id":"bf0bac994a1d8ea6","repo":"koala73/worldmonitor","slug":"expected-a-supported-two-letter-market-code","errorCode":null,"errorMessage":"Expected a supported two-letter market code","messagePattern":"Expected a supported two-letter market code","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"server/worldmonitor/consumer-prices/v1/_selection.ts","lineNumber":7,"sourceCode":"import { ValidationError } from '../../../../src/generated/server/worldmonitor/consumer_prices/v1/service_server';\n\nconst MARKETS = new Set(['ae', 'sa', 'ch', 'sg', 'us', 'gb', 'br', 'in', 'au', 'ke']);\n\nexport function resolveConsumerPriceSelection(marketCode = '', basketSlug = ''): { market: string; basket: string } {\n  if (marketCode.length > 2) {\n    throw new ValidationError([{ field: 'marketCode', description: 'Expected a supported two-letter market code' }]);\n  }\n  const market = marketCode.toLowerCase() || 'ae';\n  if (!MARKETS.has(market)) {\n    throw new ValidationError([{ field: 'marketCode', description: 'Expected a supported two-letter market code' }]);\n  }\n  if (basketSlug.length > 13) {\n    throw new ValidationError([{ field: 'basketSlug', description: 'Expected the essentials basket for the selected market' }]);\n  }\n  const basket = basketSlug.toLowerCase() || `essentials-${market}`;\n  if (basket !== `essentials-${market}`) {\n    throw new ValidationError([{ field: 'basketSlug', description: 'Expected the essentials basket for the selected market' }]);\n  }\n  return { market, basket };\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/server/worldmonitor/consumer-prices/v1/_selection.ts#L1-L22","documentation":"resolveConsumerPriceSelection validates the market code: if it is longer than 2 characters it throws ValidationError('Expected a supported two-letter market code'). Markets must be a two-letter code from the supported set (ae, sa, ch, sg, us, gb, br, in, au, ke), defaulting to 'ae'.","triggerScenarios":"Calling a consumer-prices endpoint with marketCode of length >2, e.g. market=USA, market=are, or a full country name passed in the query/path.","commonSituations":"Passing a three-letter ISO-3166 alpha-3 code (USA, GBR) instead of alpha-2; passing locale strings like 'en-US'; concatenated market+basket values.","solutions":["Send a two-letter market code from the supported list (ae, sa, ch, sg, us, gb, br, in, au, ke)","Convert ISO alpha-3 codes to alpha-2 client-side before the call","Truncate/validate the market input to max length 2 before calling","Omit the market parameter to use the 'ae' default"],"exampleFix":"// before\ngetConsumerPrices({ market: 'USA' });\n// after\nconst alpha2 = { USA: 'us', GBR: 'gb' }[code] ?? code.slice(0, 2).toLowerCase();\ngetConsumerPrices({ market: alpha2 });","handlingStrategy":"validation","validationCode":"if (typeof market !== 'string' || market.length > 2) throw new Error('market must be <=2 chars');","typeGuard":"const isShortMarketCode = (m) => typeof m === 'string' && m.length <= 2;","tryCatchPattern":"try { return await getConsumerPrices({ market }); } catch (e) { if (e?.fieldViolations?.[0]?.field === 'marketCode') { return getConsumerPrices({ market: normalizeMarket(market) }); } throw e; }","preventionTips":["Always convert ISO alpha-3 / locale codes to alpha-2 before calls","Keep a shared client constant mirroring the server market list","Validate market input at the form/URL parsing layer","Never concatenate market with other qualifiers"],"tags":["validation","consumer-prices","api"],"backgroundTag":"invalid-argument-format","analyzedSha":"e586b8b4b80f595aa7ece295eec10d76f2921240","analyzedAt":"2026-09-22T01:50:49.965Z","contentChangedAt":"2026-09-22T01:50:49.965Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}