{"record":{"id":"b191888a521d40ca","repo":"jd-opensource/joyagent-jdgenie","slug":"url-response-message","errorCode":null,"errorMessage":"调用接口\" + url + \"失败:\" + response.message()","messagePattern":"调用接口\" \\+ url \\+ \"失败:\" \\+ response\\.message\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/agent/util/OkHttpUtil.java","lineNumber":88,"sourceCode":"                .build();\n    }\n\n    public static Response postNew(String url, Map<String, String> header, String jsonBody) throws IOException {\n        OkHttpClient httpClient = getOkHttpClient();\n        RequestBody body = RequestBody.create(jsonBody, JSON);\n        Request.Builder builder = new Request.Builder().url(url).post(body);\n        if (!Objects.isNull(header)) {\n            header.forEach(builder::addHeader);\n        }\n\n        return httpClient.newCall(builder.build()).execute();\n    }\n\n    public static String postJsonBody(String url, Map<String, String> headers, String jsonBody) throws IOException {\n        log.info(\"post调用接口{}参数：{},{}\", url, jsonBody, headers);\n        try (Response response = postNew(url, headers, jsonBody)) {\n            if (!response.isSuccessful()) {\n                throw new RuntimeException(\"调用接口\" + url + \"失败:\" + response.message());\n            }\n            return Objects.requireNonNull(response.body()).string();\n        }\n    }\n\n    /**\n     * 发送 POST 请求，以 JSON 格式传递参数\n     *\n     * @param url        请求的 URL\n     * @param jsonParams JSON 格式的参数\n     * @return 请求结果\n     * @throws IOException 网络请求异常\n     */\n    public static String postJson(String url, String jsonParams, Map<String, String> headers, Long timeout) throws IOException {\n        OkHttpClient client = createClient(timeout, timeout, timeout);\n        RequestBody body = RequestBody.create(jsonParams, JSON);\n        Request.Builder requestBuilder = new Request.Builder()\n                .url(url)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/agent/util/OkHttpUtil.java#L70-L106","documentation":"OkHttpUtil.postJsonBody performs an HTTP POST and wraps any non-successful response into an unchecked RuntimeException that embeds the target URL and the HTTP status reason phrase. It is a generic transport-level failure signal, not a typed HTTP exception.","triggerScenarios":"Any postJsonBody call where the server returns a non-2xx response (4xx client error, 5xx server error, proxy rejection) — postNew returns a Response whose isSuccessful() is false.","commonSituations":"Downstream service returns 500 during an outage; auth token expired yielding 401; wrong URL path giving 404; gateway rate-limiting with 429.","solutions":["Log the full response body and status code (response.code(), not just message()) to identify the real cause.","Check target service health/auth and correct the URL or credentials.","Add retry with backoff for transient 5xx/429, and prefer a typed exception carrying the status code."],"exampleFix":"// before\nif (!response.isSuccessful()) {\n    throw new RuntimeException(\"调用接口\" + url + \"失败:\" + response.message());\n}\n// after\nif (!response.isSuccessful()) {\n    throw new IOException(\"调用接口\" + url + \"失败: HTTP \" + response.code()\n        + \" \" + response.message() + \" body=\" + peekBody(response));\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight reachability check\nHttpResponseProbe.probe(url, headers, 3); // ensure endpoint is reachable/authenticated before POST","typeGuard":null,"tryCatchPattern":"try {\n    return OkHttpUtil.postJsonBody(url, headers, jsonBody);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"调用接口\")) {\n        // parse URL from message, log, retry with backoff or failover\n    } else throw e;\n}","preventionTips":["Log response code and body, not just message(), on failure.","Use timeouts and retry-with-backoff for transient 5xx/429.","Verify auth tokens and URL correctness before calls.","Monitor downstream service health."],"tags":["java","okhttp","http","network"],"backgroundTag":"http-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"}