{"record":{"id":"71b8c5de99cba809","repo":"jd-opensource/joyagent-jdgenie","slug":"tablerag-server-return-error","errorCode":null,"errorMessage":"tableRag server return error","messagePattern":"tableRag server return error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/TableRagService.java","lineNumber":48,"sourceCode":"    public List<ChatSchemaDto> tableRag(NL2SQLReq req) throws IOException {\n        if (!dataAgentConfig.getEsConfig().getEnable() && !dataAgentConfig.getQdrantConfig().getEnable()) {\n            log.info(\"{},{} 未开启向量和es，不进行tableRag\",req.getTraceId(),req.getRequestId());\n            return new ArrayList<>();\n        }\n        String res;\n        try {\n            res = OkHttpUtil.postJsonBody(dataAgentConfig.getAgentUrl() + TABLE_RAG_URL, null, JSONObject.toJSONString(req));\n        } catch (Exception e) {\n            log.warn(\"{},{} tableRag server error,retry:{}\",req.getTraceId(),req.getRequestId(), e.getMessage());\n            res = OkHttpUtil.postJsonBody(dataAgentConfig.getAgentUrl() + TABLE_RAG_URL, null, JSONObject.toJSONString(req));\n        }\n        log.info(\"{},{} tableRag result:{}\", req.getTraceId(),req.getRequestId(),res);\n        TableRagResult tableRagResult = JSONObject.parseObject(res, TableRagResult.class);\n        if (tableRagResult == null || tableRagResult.getCode() == null) {\n            throw new RuntimeException(\"tableRag result is null\");\n        }\n        if (tableRagResult.getCode() != 200) {\n            throw new RuntimeException(\"tableRag server return error\");\n        }\n        List<TableRagResult.TableRagData> data = tableRagResult.getData();\n        if (CollectionUtils.isEmpty(data)) {\n            throw new RuntimeException(\"tableRag result data is empty\");\n        }\n        return data.stream()\n                .filter(Objects::nonNull)\n                .map(TableRagResult.TableRagData::getSchemaList)\n                .filter(CollectionUtils::isNotEmpty)\n                .flatMap(Collection::stream)\n                .collect(Collectors.toList());\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":62,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/TableRagService.java#L30-L62","documentation":"Thrown by TableRagService.tableRag when the remote table-RAG service responded with a parseable envelope whose code field is not 200. The service is reachable but reported a business-level failure for the request.","triggerScenarios":"POST to dataAgentConfig.getAgentUrl() + TABLE_RAG_URL succeeds and returns JSON like {\"code\":500,...}; any non-200 business code from the data agent triggers this exact branch.","commonSituations":"Malformed or oversized query sent to the data agent; data-agent internal error (invalid collection, service overload); API contract change where the agent now returns 4xx/5xx-style codes in the body; wrong environment endpoint that rejects the request.","solutions":["Log tableRagResult.getMessage()/body alongside code to learn the actual upstream failure reason.","Inspect data-agent server logs using req.getTraceId()/req.getRequestId() to find the root cause.","Validate the request payload (query text, table filters) against the data-agent API contract.","Add specific handling/retry for transient upstream codes (e.g., 429/503) instead of a generic RuntimeException."],"exampleFix":"// before\nif (tableRagResult.getCode() != 200) {\n    throw new RuntimeException(\"tableRag server return error\");\n}\n// after\nif (tableRagResult.getCode() != 200) {\n    throw new RuntimeException(\"tableRag server return error, code=\" + tableRagResult.getCode()\n        + \", msg=\" + tableRagResult.getMessage() + \", traceId=\" + req.getTraceId());\n}","handlingStrategy":"retry","validationCode":"// preflight: check upstream reachable and expecting 200 envelope\n// curl -s -o /dev/null -w '%{http_code}' $AGENT_URL/tableRag","typeGuard":null,"tryCatchPattern":"try {\n    List<TableRagResult.TableRagData> data = tableRagService.tableRag(req);\n} catch (RuntimeException e) {\n    if (\"tableRag server return error\".equals(e.getMessage())) {\n        // inspect data-agent logs via traceId; retry only for transient codes\n    }\n    throw e;\n}","preventionTips":["Propagate the upstream code/message into your own exception for diagnosability.","Correlate with data-agent logs using traceId/requestId.","Add retry-with-backoff only for transient upstream codes (429/503)."],"tags":["upstream-service","api-error-response","http","java"],"backgroundTag":"api-error-response","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}