Skip to content

Commit

Permalink
Handle non-200 HTTP status codes in AstroGateway
Browse files Browse the repository at this point in the history
Added a check for non-200 HTTP status codes in AstroGateway and return a Failure with a RuntimeException. This ensures that errors are correctly handled and propagated, improving the system's robustness.
  • Loading branch information
kousen committed Aug 5, 2024
1 parent 13505ea commit 8c79d8f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/kousenit/astro/AstroGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public Result<AstroResponse> getResult() {
HttpResponse<String> httpResponse =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(httpResponse.statusCode());
if (httpResponse.statusCode() != 200) {
return new Failure<>(new RuntimeException("HTTP error: " + httpResponse.statusCode()));
}
return new Success<>(
objectMapper.readValue(httpResponse.body(), AstroResponse.class));
} catch (IOException | InterruptedException e) {
Expand Down

0 comments on commit 8c79d8f

Please sign in to comment.