koala73/worldmonitor · error · ValidationError

commodity must be one of wheat, corn, rice, soybeans, barley

Error message

commodity must be one of wheat, corn, rice, soybeans, barley, palmOil

What it means

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.

Source

Thrown at server/worldmonitor/resilience/v1/get-food-stocks.ts:42

};

export { normalizeFoodStocksCommodity, normalizeFoodStocksCountry };


export const getFoodStocks: ResilienceServiceHandler['getFoodStocks'] = async (
  ctx: ServerContext,
  req: GetFoodStocksRequest,
): Promise<GetFoodStocksResponse> => {
  const countryCode = normalizeFoodStocksCountry(req.countryCode ?? '');
  if (countryCode === null) {
    throw new ValidationError([{
      field: 'countryCode',
      description: 'countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WORLD',
    }]);
  }
  const commodity = normalizeFoodStocksCommodity(req.commodity ?? '');
  if (commodity === null) {
    throw new ValidationError([{
      field: 'commodity',
      description: 'commodity must be one of wheat, corn, rice, soybeans, barley, palmOil',
    }]);
  }

  try {
    const snapshot = await getCachedJson(FOOD_STOCKS_CANONICAL_KEY, true) as Record<string, unknown> | null;
    if (!snapshot || typeof snapshot !== 'object') {
      return markNoStoreFallbackResponse(ctx.request, EMPTY);
    }

    const records = flattenSnapshot(
      snapshot,
      countryCode || undefined,
      commodity || undefined,
    ).map((row) => ({
      countryCode: row.countryCode === FOOD_STOCKS_WORLD_KEY ? 'WORLD' : row.countryCode,
      commodity: row.commodity,

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Request one of the supported commodities: wheat, corn, rice, soybeans, barley, or palmOil
  2. Restrict the commodity selector in the client to the supported list
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/worldmonitor/resilience/v1/get-food-stocks.ts:42 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of koala73/worldmonitor@eeab0a219f (2026-08-21). Data as JSON: /api/errors/16f26eeb418699fd. Report an issue: GitHub.