{"record":{"id":"e88a1d6dbe3f6178","repo":"ZhuLinsen/daily_stock_analysis","slug":"not-found-e88a1d","errorCode":"not_found","errorMessage":"未找到股票 {stock_code} 的行情数据","messagePattern":"未找到股票 (.+?) 的行情数据","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"api/v1/endpoints/stocks.py","lineNumber":441,"sourceCode":"    获取指定股票的最新行情数据\n    \n    Args:\n        stock_code: 股票代码（如 600519、00700、AAPL）\n        \n    Returns:\n        StockQuote: 实时行情数据\n        \n    Raises:\n        HTTPException: 404 - 股票不存在\n    \"\"\"\n    try:\n        service = StockService()\n        \n        # 使用 def 而非 async def，FastAPI 自动在线程池中执行\n        result = service.get_realtime_quote(stock_code)\n        \n        if result is None:\n            raise HTTPException(\n                status_code=404,\n                detail={\n                    \"error\": \"not_found\",\n                    \"message\": f\"未找到股票 {stock_code} 的行情数据\"\n                }\n            )\n        \n        return StockQuote(\n            stock_code=result.get(\"stock_code\", stock_code),\n            stock_name=result.get(\"stock_name\"),\n            current_price=result.get(\"current_price\", 0.0),\n            change=result.get(\"change\"),\n            change_percent=result.get(\"change_percent\"),\n            open=result.get(\"open\"),\n            high=result.get(\"high\"),\n            low=result.get(\"low\"),\n            prev_close=result.get(\"prev_close\"),\n            volume=result.get(\"volume\"),","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/api/v1/endpoints/stocks.py#L423-L459","documentation":"Raised by GET /{stock_code}/quote in api/v1/endpoints/stocks.py when StockService.get_realtime_quote(stock_code) returns None. The endpoint executes the service call in FastAPI's threadpool (def, not async def) and maps a None result to a 404 with error code 'not_found'. It means the service layer resolved no quote data for the requested symbol, not that the HTTP layer failed.","triggerScenarios":"Calling GET /api/v1/stocks/{stock_code}/quote with a malformed or nonexistent stock code (e.g. '60051', 'XXXXXX', a delisted symbol), or a valid code whose quote fetch fails upstream in a way that yields None instead of raising.","commonSituations":"Typos in stock codes; using the wrong market prefix format (the repo supports A-share like 600519, HK like hk00700, and US like AAPL); querying during hours when the data provider returns nothing; data-source fallback returning None after all providers fail.","solutions":["Verify the stock code format matches the supported markets (A-share 6-digit, hk-prefixed, or US ticker) and retry","Test the same code through another endpoint (e.g. /{stock_code}/history) to confirm the symbol is recognized at all","Check the data provider logs/config (data_provider fallback chain) if a known-good code still returns 404","If the code is valid, inspect StockService.get_realtime_quote to see which provider returning None swallows the real upstream error"],"exampleFix":"// before\nconst res = await fetch(`/api/v1/stocks/${code}/quote`);\nconst data = await res.json(); // crashes on 404\n// after\nconst res = await fetch(`/api/v1/stocks/${code}/quote`);\nif (res.status === 404) {\n  throw new Error(`No quote for ${code}: check the symbol format`);\n}\nconst data = await res.json();","handlingStrategy":"validation","validationCode":"function isValidStockCode(code) {\n  return /^(\\d{6}|hk\\d{4,5}|[A-Za-z]{1,6})$/.test(code);\n}\n// call before GET /{stock_code}/quote","typeGuard":"function isStockQuote(d) {\n  return d != null && typeof d.stock_code === 'string' && typeof d.current_price === 'number';\n}","tryCatchPattern":"if (res.status === 404 && body.error === 'not_found') { /* treat as unknown symbol, do not retry */ }","preventionTips":["Validate stock code format client-side before calling the quote endpoint","Maintain a symbol watchlist validated once, reuse codes from it","Distinguish 404 (bad symbol) from 500 (provider failure) in error handling — only the latter is retryable"],"tags":["api","stock-data","not-found","fastapi"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}