{"record":{"id":"55ef4f9d08755284","repo":"datawhalechina/hello-agents","slug":"str-e-55ef4f","errorCode":null,"errorMessage":"路线规划失败: {str(e)}","messagePattern":"路线规划失败: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"code/chapter13/helloagents-trip-planner/backend/app/api/routes/map.py","lineNumber":136,"sourceCode":"        \n        # 规划路线\n        route_info = service.plan_route(\n            origin_address=request.origin_address,\n            destination_address=request.destination_address,\n            origin_city=request.origin_city,\n            destination_city=request.destination_city,\n            route_type=request.route_type\n        )\n        \n        return RouteResponse(\n            success=True,\n            message=\"路线规划成功\",\n            data=route_info\n        )\n        \n    except Exception as e:\n        print(f\"❌ 路线规划失败: {str(e)}\")\n        raise HTTPException(\n            status_code=500,\n            detail=f\"路线规划失败: {str(e)}\"\n        )\n\n\n@router.get(\n    \"/health\",\n    summary=\"健康检查\",\n    description=\"检查地图服务是否正常\"\n)\nasync def health_check():\n    \"\"\"健康检查\"\"\"\n    try:\n        # 检查服务是否可用\n        service = get_amap_service()\n        \n        return {\n            \"status\": \"healthy\",","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/code/chapter13/helloagents-trip-planner/backend/app/api/routes/map.py#L118-L154","documentation":"HTTPException(500) raised by POST /map/route in the chapter13 backend when service.plan_route(...) (route planning via the Amap MCP tools) throws. The route involves origin/destination coordinates or names plus a route_type, and any failure in the MCP tool chain or upstream Amap API becomes this 500.","triggerScenarios":"Origin/destination strings the geocoding sub-tools cannot resolve; missing AMAP_API_KEY; amap-mcp-server subprocess not running; malformed request fields (empty origin_city/destination_city) reaching the service.","commonSituations":"Users passing landmark names that geocode to nothing; env not configured after redeploy; upstream Amap direction API quota or coordinate-system (GPS vs GCJ-02) errors.","solutions":["Read the '❌ 路线规划失败' log line and embedded detail for the root cause","Test with simple, well-known city names (e.g. 北京 -> 上海) to rule out geocoding of obscure inputs","Confirm AMAP_API_KEY works and the direction API is enabled for it","Check /map/health before calling to detect service-init failures early"],"exampleFix":"# before\nbody = {'origin': '我家附近', 'destination': '那个商场'}  # unresolvable -> 500\n\n# after\nbody = {'origin_city': '北京', 'destination_city': '上海', 'route_type': 'driving'}\nr = requests.post(f'{BASE}/map/route', json=body)\nr.raise_for_status()","handlingStrategy":"validation","validationCode":"def valid_route_request(body: dict) -> bool:\n    return (\n        bool(str(body.get('origin_city', '')).strip())\n        and bool(str(body.get('destination_city', '')).strip())\n        and body.get('route_type') in {'driving', 'transit', 'walking', 'cycling'}\n    )","typeGuard":"def is_supported_route_type(t: str) -> bool:\n    return t in {'driving', 'transit', 'walking', 'cycling'}","tryCatchPattern":"try:\n    r = requests.post(f'{BASE}/map/route', json=body, timeout=30)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    detail = e.response.json().get('detail', '')\n    if 'geocode' in detail.lower() or '无效' in detail:\n        body['origin_city'], body['destination_city'] = '北京', '上海'  # simplified retry\n    raise","preventionTips":["Use well-known city names for routing inputs; geocode landmarks separately first","Validate route_type against the known enum before sending","Check /map/health before routing in long user sessions"],"tags":["fastapi","http-500","amap","routing"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}