{"record":{"id":"521fe2d90c2a647c","repo":"ZhuLinsen/daily_stock_analysis","slug":"unsupported-period","errorCode":"unsupported_period","errorMessage":"unsupported_period","messagePattern":"unsupported_period","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"api/v1/endpoints/stocks.py","lineNumber":540,"sourceCode":"                low=item.get(\"low\"),\n                close=item.get(\"close\"),\n                volume=item.get(\"volume\"),\n                amount=item.get(\"amount\"),\n                change_percent=item.get(\"change_percent\")\n            )\n            for item in result.get(\"data\", [])\n        ]\n        \n        return StockHistoryResponse(\n            stock_code=stock_code,\n            stock_name=result.get(\"stock_name\"),\n            period=period,\n            data=data\n        )\n    \n    except ValueError as e:\n        # period 参数不支持的错误（如 weekly/monthly）\n        raise HTTPException(\n            status_code=422,\n            detail={\n                \"error\": \"unsupported_period\",\n                \"message\": str(e)\n            }\n        )\n    except Exception as e:\n        logger.error(f\"获取历史行情失败: {e}\", exc_info=True)\n        raise HTTPException(\n            status_code=500,\n            detail={\n                \"error\": \"internal_error\",\n                \"message\": f\"获取历史行情失败: {str(e)}\"\n            }\n        )\n","sourceCodeStart":522,"sourceCodeEnd":556,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/api/v1/endpoints/stocks.py#L522-L556","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nGET /api/v1/stocks/600519/history?period=weekly  // 422 unsupported_period\n// after\nGET /api/v1/stocks/600519/history?period=daily","handlingStrategy":"validation","validationCode":"const SUPPORTED_PERIODS = new Set(['daily']); // confirm against endpoint docs\nif (!SUPPORTED_PERIODS.has(period)) throw new RangeError(`Unsupported period: ${period}`);","typeGuard":"const isSupportedPeriod = (p) => ['daily'].includes(p);","tryCatchPattern":"if (res.status === 422 && body.error === 'unsupported_period') { /* switch to a supported period or request feature */ }","preventionTips":["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"],"tags":["api","validation","query-params","stock-data"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}