{"record":{"id":"d97ddc734591801d","repo":"koala73/worldmonitor","slug":"invalid-region-only-global-is-supported","errorCode":null,"errorMessage":"Invalid region: only global is supported","messagePattern":"Invalid region: only global is supported","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"warning","filePath":"server/worldmonitor/infrastructure/v1/get-temporal-baseline.ts","lineNumber":27,"sourceCode":"import {\n  VALID_BASELINE_TYPES,\n  MIN_SAMPLES,\n  Z_THRESHOLD_LOW,\n  makeBaselineKey,\n  getBaselineSeverity,\n  type BaselineEntry,\n} from './_shared';\n\n// ========================================================================\n// RPC implementation\n// ========================================================================\n\nexport async function getTemporalBaseline(\n  _ctx: ServerContext,\n  req: GetTemporalBaselineRequest,\n): Promise<GetTemporalBaselineResponse> {\n  const region = req.region || 'global';\n  if (region !== 'global') throw new ApiError(400, 'Invalid region: only global is supported', '');\n\n  try {\n    const { type, count } = req;\n\n    if (!type || !VALID_BASELINE_TYPES.includes(type) || typeof count !== 'number' || Number.isNaN(count)) {\n      return {\n        learning: false,\n        sampleCount: 0,\n        samplesNeeded: 0,\n        error: 'Missing or invalid params: type and count required',\n      };\n    }\n\n    const now = new Date();\n    const weekday = now.getUTCDay();\n    const month = now.getUTCMonth() + 1;\n    const key = makeBaselineKey(type, region, weekday, month);\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/server/worldmonitor/infrastructure/v1/get-temporal-baseline.ts#L9-L45","documentation":"getTemporalBaseline only serves the 'global' temporal baseline dataset. The handler normalizes a missing region to 'global' and rejects any explicitly provided other value with a 400 ApiError, because no per-region baseline data is produced or seeded.","triggerScenarios":"Calling getTemporalBaseline (or its v1 HTTP endpoint) with req.region set to anything other than 'global' — e.g. 'us', 'europe', 'emea', or a country code. Omitting region is fine (defaults to 'global').","commonSituations":"A client that also calls region-scoped endpoints (coverage, energy profile) reuses the same region field for the baseline request; UI country filters forwarded blindly to all endpoints; proto clients filling the region field with a default like 'us-east-1'.","solutions":["Remove the region field from the request (or set it to 'global') and filter client-side instead.","Update callers so region-scoped logic goes through the region-aware endpoints rather than getTemporalBaseline.","If per-region baselines are genuinely needed, extend the backend seeding to produce regional baselines before passing region here."],"exampleFix":"// before\nawait client.getTemporalBaseline({ region: selectedCountry });\n// after\nawait client.getTemporalBaseline({ region: 'global' }); // or omit region\nconst scoped = baseline.events.filter((e) => e.countryCode === selectedCountry);","handlingStrategy":"validation","validationCode":"if (typeof region === 'string' && region !== 'global') throw new Error('getTemporalBaseline supports only region \"global\"; omit the field or use \"global\".');","typeGuard":null,"tryCatchPattern":"try {\n  const baseline = await client.getTemporalBaseline({ region: 'global' });\n} catch (e) {\n  if (e.status === 400 && /only global is supported/.test(e.message)) {\n    // stop sending region to this endpoint; filter client-side\n  }\n}","preventionTips":["Omit the region field for baseline requests instead of forwarding UI filters.","Keep a shared request-builder per endpoint so region-scoped params only go to region-aware endpoints.","Document in the client wrapper that baseline is global-only."],"tags":["validation","unsupported-region","api"],"backgroundTag":"invalid-argument-value","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}