koala73/worldmonitor · error · ValidationError

countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WO

Error message

countryCode must be a 2-letter ISO 3166-1 alpha-2 code or WORLD

What it means

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.

Source

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

} from './_food-stocks-query';

const EMPTY: GetFoodStocksResponse = {
  records: [],
  fetchedAt: '',
  unavailable: true,
  calorieWeightedStocksToUse: 0,
};

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);
    }

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Use a valid alpha-2 country code or 'WORLD'
  2. Offer only the supported country list (plus WORLD) in the client selector
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/worldmonitor/resilience/v1/get-food-stocks.ts:35 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/b8747dc29a2b7efd. Report an issue: GitHub.