Skip to content

Commit

Permalink
fix: Fail early if IMDS returns an error. (#298)
Browse files Browse the repository at this point in the history
This catches errors earlier on OCI for example, where the PUT request
returns 405.
  • Loading branch information
bgrozev authored Dec 5, 2024
1 parent 7846e6c commit 4f13296
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ private static String fetch(String url, Map<String, String> headers, String meth
builder.setHeader(header.getKey(), header.getValue());
}
HttpResponse<String> response = httpClient.send(builder.build(), HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200)
{
throw new Exception("Failed to fetch " + url + ". Response code: " + response.statusCode());
}
return response.body();
}
}

0 comments on commit 4f13296

Please sign in to comment.