elastic/elasticsearch · error · GradleException
Uploading Snyk Graph failed with http code {}: {}
Error message
Uploading Snyk Graph failed with http code {}: {} What it means
GradleException thrown when the Snyk dependency-graph HTTP PUT returns any status other than HTTP 201 Created. The message includes the status code and the raw response body so the API's error text is surfaced.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/snyk/UploadSnykDependenciesGraph.java:72
token = objectFactory.property(String.class);
inputFile = objectFactory.fileProperty();
}
@TaskAction
void upload() {
String endpoint = calculateEffectiveEndpoint();
CloseableHttpResponse response;
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpPut putRequest = new HttpPut(endpoint);
putRequest.addHeader("Authorization", "token " + token.get());
putRequest.addHeader("Content-Type", "application/json");
putRequest.setEntity(new FileEntity(inputFile.getAsFile().get(), ContentType.APPLICATION_JSON));
response = client.execute(putRequest);
int statusCode = response.getCode();
String responseString = EntityUtils.toString(response.getEntity());
getLogger().info("Snyk API call response status: " + statusCode);
if (statusCode != HttpURLConnection.HTTP_CREATED) {
throw new GradleException("Uploading Snyk Graph failed with http code " + statusCode + ": " + responseString);
}
getLogger().info(responseString);
} catch (IOException | ParseException e) {
throw new GradleException("Failed to call API endpoint to submit updated dependency graph", e);
}
}
private String calculateEffectiveEndpoint() {
String url = this.url.get();
return snykOrganisation.map(id -> url + "?org=" + id).getOrElse(url);
}
@Input
public Property<String> getToken() {
return token;
}
@InputView on GitHub (pinned to db6a809a66)
Solutions
- Read the response body in the message to see Snyk's specific error reason first.
- Confirm the token is valid: rotate/re-check the Authorization header value for token.get().
- Validate calculateEffectiveEndpoint() produces the correct Snyk API URL including the right org id.
- If 429/5xx, retry with backoff or re-run the upload task later.
Example fix
// before
if (statusCode != HttpURLConnection.HTTP_CREATED) {
throw new GradleException("Uploading Snyk Graph failed with http code " + statusCode + ": " + responseString);
}
// after - tolerate 200/201 and surface Snyk request id
if (statusCode != HttpURLConnection.HTTP_CREATED && statusCode != HttpURLConnection.HTTP_OK) {
throw new GradleException("Uploading Snyk Graph failed with http code " + statusCode + ": " + responseString);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the token and endpoint shape before uploading
if (token.get() == null || token.get().isBlank()) {
throw new GradleException("Snyk token not set; skipping upload");
}
String endpoint = calculateEffectiveEndpoint();
if (!endpoint.startsWith("https://")) {
throw new GradleException("Snyk endpoint must be https: " + endpoint);
} Try / catch
try {
// upload logic
} catch (GradleException e) {
if (e.getMessage().contains("failed with http code")) {
getLogger().warn("Snyk upload rejected: {}", e.getMessage());
// surface but do not fail the build if upload is best-effort
return;
}
throw e;
} Prevention
- Rotate and verify the Snyk token before running the upload task.
- Confirm the org id and endpoint URL in the task configuration.
- Treat the upload as best-effort (continue-on-error) if Snyk availability is not release-critical.
When it happens
Trigger: client.execute(putRequest) returns a non-201 code: 401/403 for a bad or expired token, 404 for a wrong endpoint URL, 422 for a malformed payload, 429 for rate limiting, or 5xx for a Snyk-side outage.
Common situations: SNYK_TOKEN expired or revoked; organisation id omitted or wrong causing the ?org= query to resolve to a forbidden org; payload JSON schema drifted from Snyk API expectations; network proxy rewriting the response.
Related errors
- Failed to call API endpoint to submit updated dependency gra
- Failed to download branches.json from: {}
- Cannot generate dependencies json file
- Interrupted while retrying download from: {}
- too many redirects connection to [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/2175dad2308587fb.
Report an issue: GitHub.