From 762d7b2899754e36655f0e243031b594135f3773 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Thu, 8 Sep 2022 15:13:59 +0200 Subject: [PATCH 1/3] :alien: Change bad gateway code to 502 to match Reverse Proxy Apache/Nginx return 502 when the service container is not reachable. Adapt to this HTTP status code to make error handling in the client easier. --- src/main/java/de/netz39/svc/pwrMtrPlsGw/PulseEndpoint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/netz39/svc/pwrMtrPlsGw/PulseEndpoint.java b/src/main/java/de/netz39/svc/pwrMtrPlsGw/PulseEndpoint.java index 6586190..7f42dec 100644 --- a/src/main/java/de/netz39/svc/pwrMtrPlsGw/PulseEndpoint.java +++ b/src/main/java/de/netz39/svc/pwrMtrPlsGw/PulseEndpoint.java @@ -41,7 +41,7 @@ public class PulseEndpoint { @Operation(summary = "Send a pulse message") @ApiResponse(responseCode = "201", description = "AMQP call successful") @ApiResponse(responseCode = "400", description = "Invalid call arguments") - @ApiResponse(responseCode = "504", description = "Timeout or error while connecting to RabbitMQ, please retry later!") + @ApiResponse(responseCode = "502", description = "Timeout or error while connecting to RabbitMQ, please retry later!") public HttpStatus pulse(@Body PulseMessage body, @Parameter(description = "Authorization string as `Beaker `, see README for details") @Header(HttpHeaders.AUTHORIZATION) @Nullable String authorization) { @@ -67,6 +67,6 @@ boolean isValidAuth(final String authorization) { @Error(exception=RabbitClientException.class) public HttpResponse onRabbitClientException(RabbitClientException e) { - return HttpResponse.status(HttpStatus.GATEWAY_TIMEOUT).body(e.getMessage()); + return HttpResponse.status(HttpStatus.BAD_GATEWAY).body(e.getMessage()); } } From d4338f768d929fbe5c685522a9f9bd4035abfa81 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Thu, 8 Sep 2022 15:14:53 +0200 Subject: [PATCH 2/3] :hammer: Adapt test case to changed API --- src/test/java/de/netz39/svc/pwrMtrPlsGw/TestPulseEndpoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/de/netz39/svc/pwrMtrPlsGw/TestPulseEndpoint.java b/src/test/java/de/netz39/svc/pwrMtrPlsGw/TestPulseEndpoint.java index c618ddb..16dd0a9 100644 --- a/src/test/java/de/netz39/svc/pwrMtrPlsGw/TestPulseEndpoint.java +++ b/src/test/java/de/netz39/svc/pwrMtrPlsGw/TestPulseEndpoint.java @@ -89,7 +89,7 @@ public void testMissingRabbitMQ() { HttpClientResponseException.class, () -> client.toBlocking().exchange(req) ); - assertEquals(HttpStatus.GATEWAY_TIMEOUT.getCode(), e.getStatus().getCode()); + assertEquals(HttpStatus.BAD_GATEWAY.getCode(), e.getStatus().getCode()); } @Test From c4e88c9f8961c356b139b58fbddb0a6d1935ba23 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Thu, 8 Sep 2022 15:16:01 +0200 Subject: [PATCH 3/3] :memo: Adapt to API change and mention reverse proxy status code --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b8fca8..a9851df 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,10 @@ This call returns one of the following codes: * `201` if the call was successful (created) * `400` if the body argument is invalid * `401` if authorization failed -* `504` if the AMQP queue is not available. +* `502` if the AMQP queue is not available. -On return code `504` the call should be retried at a later point. In any other case the call should not be retried. +On return code `502` the call should be retried at a later point. In any other case the call should not be retried. +A `502` status code may also be returned by the reverse proxy if the service container is not running. Please note that idempotency is not considered by the gateway in the sense that an already sent timestamp will not be suppressed.