Skip to content

Commit

Permalink
[PRMT-4678] - Added try-with-resources block in httpClient (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadIqbalAD-NHS authored Mar 26, 2024
1 parent 2bd4d86 commit cb5f65a
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ public StoreMessageResponseBody confirmMessageStored(ParsedMessage parsedMessage
.header("traceId", tracer.getTraceId())
.POST(jsonPayload).build();

var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());

try (var httpClient = HttpClient.newHttpClient()) {
var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

if (response.statusCode() != 201) {
throw new HttpException(String.format("Unexpected response from EHR while checking if a message was stored: %d", response.statusCode()));
if (response.statusCode() != 201) {
throw new HttpException(String.format("Unexpected response from EHR while checking if a message was stored: %d", response.statusCode()));
}
return parseResponse(response);
} catch (Exception exception) {
throw new RuntimeException("Error encountered when uploading message to S3", exception);
}
return parseResponse(response);
}

public void softDeleteEhrRecord(String nhsNumber) {
Expand Down

0 comments on commit cb5f65a

Please sign in to comment.