{"record":{"id":"921a06bb388135cb","repo":"theonedev/onedev","slug":"http-request-failed-url-s-status-code-d-err","errorCode":null,"errorMessage":"Http request failed (url: %s, status code: %d, error message: %s)","messagePattern":"Http request failed \\(url: (.+?), status code: (.+?), error message: (.+?)\\)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/util/JerseyUtils.java","lineNumber":41,"sourceCode":"\t\t\t\treturn String.format(\"Http request failed (url: %s, status code: %d, error message: %s)\", \n\t\t\t\t\t\turl, status, errorMessage);\n\t\t\t} else {\n\t\t\t\treturn String.format(\"Http request failed (url: %s, status code: %d)\", url, status);\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\t\n\tpublic static JsonNode get(Client client, String apiEndpoint, TaskLogger logger) {\n\t\tWebTarget target = client.target(apiEndpoint);\n\t\tInvocation.Builder builder =  target.request();\n\t\ttry (Response response = builder.get()) {\n\t\t\tint status = response.getStatus();\n\t\t\tif (status != 200) {\n\t\t\t\tString errorMessage = response.readEntity(String.class);\n\t\t\t\tif (StringUtils.isNotBlank(errorMessage)) {\n\t\t\t\t\tthrow new ExplicitException(String.format(\"Http request failed (url: %s, status code: %d, error message: %s)\", \n\t\t\t\t\t\t\tapiEndpoint, status, errorMessage));\n\t\t\t\t} else {\n\t\t\t\t\tthrow new ExplicitException(String.format(\"Http request failed (status: %s)\", status));\n\t\t\t\t}\n\t\t\t} \n\t\t\treturn response.readEntity(JsonNode.class);\n\t\t}\n\t}\n\t\n\tpublic static interface PageDataConsumer {\n\t\t\n\t\tvoid consume(List<JsonNode> pageData) throws InterruptedException;\n\t\t\n\t}\n\t\n}\n","sourceCodeStart":23,"sourceCodeEnd":58,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/util/JerseyUtils.java#L23-L58","documentation":"JerseyUtils.get performs a GET against an API endpoint expecting HTTP 200 and a JSON body. On any non-200 status with a non-blank error body, it throws ExplicitException formatted with the url, status code, and server-provided error message. ExplicitException indicates an anticipated, user-facing failure of the remote API call.","triggerScenarios":"Calling JerseyUtils.get(apiEndpoint) and receiving 4xx/5xx with a readable error body — invalid URL path, expired/insufficient credentials, missing permissions on the target resource, or server-side errors that include a message entity.","commonSituations":"Wrong endpoint or resource id (404), revoked access token (401/403), rate limiting (429) with error body, or upstream service 5xx responses carrying JSON/text error payloads.","solutions":["Read the error message in the exception — it comes from the remote server and usually states the real problem.","Verify the apiEndpoint URL and resource id are correct and the resource exists.","Check authentication: token validity, scopes, and permissions for the accessed resource.","Retry on 429/5xx with backoff; check server health if 5xx persists.","Use tools like curl on the same URL with the same credentials to reproduce outside the application."],"exampleFix":"// before\nJsonNode node = JerseyUtils.get(\"https://host/api/bad-resource\"); // 404 with error body -> ExplicitException\n// after\nString url = \"https://host/api/correct-resource\"; // verify with curl first\nJsonNode node = JerseyUtils.get(url);","handlingStrategy":"try-catch","validationCode":"// preflight\nResponse r = client.target(apiEndpoint).request().get();\n// check credentials/URL beforehand; validate endpoint pattern\nif (!apiEndpoint.startsWith(\"https://\") ) throw new IllegalArgumentException(\"Invalid endpoint\");","typeGuard":null,"tryCatchPattern":"try {\n    JsonNode node = JerseyUtils.get(apiEndpoint);\n} catch (ExplicitException e) {\n    // message contains url, status, and server error body — log and surface to user\n    log.error(\"API GET failed: {}\", e.getMessage());\n}","preventionTips":["Validate endpoint URLs and resource ids before calling.","Keep tokens fresh and scoped to required resources.","Implement retry with backoff for 429/5xx statuses.","Reproduce failures with curl against the same endpoint."],"tags":["http","rest","jersey","api"],"backgroundTag":"http-error-response","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}