ZhuLinsen/daily_stock_analysis · warning · HTTPException
unsupported_period
unsupported_period
Error message
unsupported_period
What it means
Raised by GET /{stock_code}/history when the service raises ValueError for an unsupported period parameter (the comment explicitly names weekly/monthly). The endpoint maps ValueError to 422 with error code 'unsupported_period' and passes the exception text through as the message.
Source
Thrown at api/v1/endpoints/stocks.py:540
low=item.get("low"),
close=item.get("close"),
volume=item.get("volume"),
amount=item.get("amount"),
change_percent=item.get("change_percent")
)
for item in result.get("data", [])
]
return StockHistoryResponse(
stock_code=stock_code,
stock_name=result.get("stock_name"),
period=period,
data=data
)
except ValueError as e:
# period 参数不支持的错误(如 weekly/monthly)
raise HTTPException(
status_code=422,
detail={
"error": "unsupported_period",
"message": str(e)
}
)
except Exception as e:
logger.error(f"获取历史行情失败: {e}", exc_info=True)
raise HTTPException(
status_code=500,
detail={
"error": "internal_error",
"message": f"获取历史行情失败: {str(e)}"
}
)
View on GitHub (pinned to 5159bd72e8)
Solutions
- Use a supported period value (check the endpoint's period Query parameter docs / StockHistoryResponse examples, e.g. daily)
- If weekly/monthly data is required, extend the service history method to support them rather than catching the 422 client-side
- Read the returned message — it is str(e) from the service and names the unsupported value
Example fix
// before GET /api/v1/stocks/600519/history?period=weekly // 422 unsupported_period // after GET /api/v1/stocks/600519/history?period=daily
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_PERIODS = new Set(['daily']); // confirm against endpoint docs
if (!SUPPORTED_PERIODS.has(period)) throw new RangeError(`Unsupported period: ${period}`); Type guard
const isSupportedPeriod = (p) => ['daily'].includes(p);
Try / catch
if (res.status === 422 && body.error === 'unsupported_period') { /* switch to a supported period or request feature */ } Prevention
- Derive the period dropdown values from the API's OpenAPI schema, not hardcoded assumptions
- Pin frontend and backend versions together so period vocabularies stay in sync
When it happens
Trigger: Calling GET /api/v1/stocks/{stock_code}/history?period=weekly or ?period=monthly (or any period string outside the supported set) — the service validates period and raises ValueError before any data fetch.
Common situations: Clients assuming the API supports the same periods as the web UI; version drift where a newer frontend sends weekly/monthly but the deployed backend only accepts daily-style periods; copy-pasting period values from another API.
Related errors
- not_found
- validation_failed
- {field_name} must be one of: {allowed}
- Backend executable not found: ${backendPath}
- Invalid share image record ID
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/521fe2d90c2a647c.
Report an issue: GitHub.