Skip to content

Commit 7f41b02

Browse files
committed
Ignore server errors while waiting for final status
Closes gh-15
1 parent c8fdc1d commit 7f41b02

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

action/src/main/java/io/spring/github/actions/centralpublish/sonatype/CentralPortalApiImpl.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.util.CollectionUtils;
3939
import org.springframework.util.LinkedMultiValueMap;
4040
import org.springframework.util.MultiValueMap;
41+
import org.springframework.util.StreamUtils;
4142
import org.springframework.util.unit.DataSize;
4243
import org.springframework.web.client.RestClient;
4344

@@ -175,7 +176,12 @@ public void awaitFinalStatus() {
175176
}
176177
catch (DeploymentNotFoundException ex) {
177178
// Sometimes Sonatype returns 404 for newly created deployments
178-
this.logger.debug("Got 404 while checking status");
179+
this.logger.debug(ex.getMessage());
180+
sleep();
181+
continue;
182+
}
183+
catch (InternalServerErrorException ex) {
184+
this.logger.log(ex.getMessage());
179185
sleep();
180186
continue;
181187
}
@@ -216,8 +222,13 @@ private DeploymentStatusDto fetchDeploymentStatus() {
216222
return this.restClient.post()
217223
.uri("/api/v1/publisher/status?id={deploymentId}", this.deploymentId)
218224
.retrieve()
219-
.onStatus(this::is404, (res, req) -> {
220-
throw new DeploymentNotFoundException();
225+
.onStatus(this::is404, (req, res) -> {
226+
throw new DeploymentNotFoundException(res.getStatusCode(), res.getStatusText(),
227+
StreamUtils.copyToString(res.getBody(), StandardCharsets.UTF_8));
228+
})
229+
.onStatus(HttpStatusCode::is5xxServerError, (req, res) -> {
230+
throw new InternalServerErrorException(res.getStatusCode(), res.getStatusText(),
231+
StreamUtils.copyToString(res.getBody(), StandardCharsets.UTF_8));
221232
})
222233
.body(DeploymentStatusDto.class);
223234
}
@@ -243,6 +254,21 @@ private static final class DeploymentNotFoundException extends RuntimeException
243254
@Serial
244255
private static final long serialVersionUID = 1L;
245256

257+
DeploymentNotFoundException(HttpStatusCode statusCode, String statusText, String body) {
258+
super("Got %d '%s' while checking status. Body:\n%s".formatted(statusCode.value(), statusText, body));
259+
}
260+
261+
}
262+
263+
private static final class InternalServerErrorException extends RuntimeException {
264+
265+
@Serial
266+
private static final long serialVersionUID = 1L;
267+
268+
InternalServerErrorException(HttpStatusCode statusCode, String statusText, String body) {
269+
super("Got %d '%s' while checking status. Body:\n%s".formatted(statusCode.value(), statusText, body));
270+
}
271+
246272
}
247273

248274
}

0 commit comments

Comments
 (0)