{"record":{"id":"16f26eeb418699fd","repo":"koala73/worldmonitor","slug":"commodity-must-be-one-of-wheat-corn-rice-soybea","errorCode":null,"errorMessage":"commodity must be one of wheat, corn, rice, soybeans, barley, palmOil","messagePattern":"commodity must be one of wheat, corn, rice, soybeans, barley, palmOil","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"server/worldmonitor/resilience/v1/get-food-stocks.ts","lineNumber":42,"sourceCode":"};\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\n    const records = flattenSnapshot(\n      snapshot,\n      countryCode || undefined,\n      commodity || undefined,\n    ).map((row) => ({\n      countryCode: row.countryCode === FOOD_STOCKS_WORLD_KEY ? 'WORLD' : row.countryCode,\n      commodity: row.commodity,","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/server/worldmonitor/resilience/v1/get-food-stocks.ts#L24-L60","documentation":"Request validation in the getFoodStocks handler: req.commodity failed normalizeFoodStocksCommodity — only wheat, corn, rice, soybeans, barley, and palmOil are supported. Other commodities are rejected before any cache read, since no data exists for them.","triggerScenarios":"Thrown at server/worldmonitor/resilience/v1/get-food-stocks.ts:42 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Request one of the supported commodities: wheat, corn, rice, soybeans, barley, or palmOil","Restrict the commodity selector in the client to the supported list"],"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"}