Skip to content

Commit

Permalink
[PRMT-4678] - Added try-with-resources block in httpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadIqbalAD-NHS committed Mar 26, 2024
1 parent 758912c commit b6f289c
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 b6f289c

Please sign in to comment.