Skip to content

Commit

Permalink
Include hangar error message in exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Dec 30, 2023
1 parent a68a912 commit a623156
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public void uploadVersion(final HangarPublication publication) throws IOExceptio
final HangarAuthorizationToken jwt = this.auth.jwt(client, publication.getApiEndpoint().get(), publication.getApiKey().get());
post.addHeader("Authorization", jwt.getJwt());

final String[] error = new String[1];
final @Nullable String result = client.execute(post, response -> {
if (response.getCode() != 200) {
LOGGER.error("Error uploading version, returned {}: {}", response.getCode(), ErrorResponseParser.parse(response));
error[0] = "Error uploading version, returned " + response.getCode() + ": " + ErrorResponseParser.parse(response);
return null;
}
return GSON.fromJson(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8), JsonObject.class).get("url").getAsString();
Expand All @@ -87,7 +88,7 @@ public void uploadVersion(final HangarPublication publication) throws IOExceptio
if (result != null) {
LOGGER.lifecycle("Successfully published {} version {} to Hangar: {}", publication.getId().get(), publication.getVersion().get(), result);
} else {
throw new RuntimeException("Error uploading version");
throw new RuntimeException(error[0] != null ? error[0] : "Unknown error uploading version");
}
}
}
Expand Down

0 comments on commit a623156

Please sign in to comment.