{"record":{"id":"b8747dc29a2b7efd","repo":"koala73/worldmonitor","slug":"countrycode-must-be-a-2-letter-iso-3166-1-alpha-2-b8747d","errorCode":null,"errorMessage":"countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WORLD","messagePattern":"countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WORLD","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"server/worldmonitor/resilience/v1/get-food-stocks.ts","lineNumber":35,"sourceCode":"} from './_food-stocks-query';\n\nconst EMPTY: GetFoodStocksResponse = {\n  records: [],\n  fetchedAt: '',\n  unavailable: true,\n  calorieWeightedStocksToUse: 0,\n};\n\nexport { normalizeFoodStocksCommodity, normalizeFoodStocksCountry };\n\n\nexport const getFoodStocks: ResilienceServiceHandler['getFoodStocks'] = async (\n  ctx: ServerContext,\n  req: GetFoodStocksRequest,\n): Promise<GetFoodStocksResponse> => {\n  const countryCode = normalizeFoodStocksCountry(req.countryCode ?? '');\n  if (countryCode === null) {\n    throw new ValidationError([{\n      field: 'countryCode',\n      description: 'countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WORLD',\n    }]);\n  }\n  const commodity = normalizeFoodStocksCommodity(req.commodity ?? '');\n  if (commodity === null) {\n    throw new ValidationError([{\n      field: 'commodity',\n      description: 'commodity must be one of wheat, corn, rice, soybeans, barley, palmOil',\n    }]);\n  }\n\n  try {\n    const snapshot = await getCachedJson(FOOD_STOCKS_CANONICAL_KEY, true) as Record<string, unknown> | null;\n    if (!snapshot || typeof snapshot !== 'object') {\n      return markNoStoreFallbackResponse(ctx.request, EMPTY);\n    }\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/server/worldmonitor/resilience/v1/get-food-stocks.ts#L17-L53","documentation":"Request validation in the getFoodStocks handler: req.countryCode failed normalizeFoodStocksCountry — it must be a 2-letter ISO 3166-1 alpha-2 code or the literal 'WORLD' for global aggregates. Anything else is rejected before the food-stocks cache is read.","triggerScenarios":"Thrown at server/worldmonitor/resilience/v1/get-food-stocks.ts:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a valid alpha-2 country code or 'WORLD'","Offer only the supported country list (plus WORLD) in the client selector"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}