From 6208c0d77a48de13dc93cc925ba2cfccd9778484 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:25:00 -0700 Subject: [PATCH] Fix variables serialization bug in TestProxyRecordPolicy (#37075) --- .../core/test/policy/TestProxyRecordPolicy.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java index b1bcf125ba887..51a241a27118a 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java @@ -104,13 +104,21 @@ private void setDefaultRecordingOptions() { /** * Stops recording of test traffic. * @param variables A list of random variables generated during the test which is saved in the recording. + * @throws RuntimeException If the test proxy returns an error while stopping recording. */ public void stopRecording(Queue variables) { HttpRequest request = new HttpRequest(HttpMethod.POST, proxyUrl + "/record/stop") .setHeader(HttpHeaderName.CONTENT_TYPE, "application/json") .setHeader(X_RECORDING_ID, xRecordingId) .setBody(serializeVariables(variables)); - client.sendSync(request, Context.NONE).close(); + + try (HttpResponse response = client.sendSync(request, Context.NONE)) { + checkForTestProxyErrors(response); + + if (response.getStatusCode() == 400) { + throw new RuntimeException(response.getBodyAsBinaryData().toString()); + } + } } /** @@ -138,7 +146,7 @@ private String serializeVariables(Queue variables) { if (variable == null) { builder.append("null"); } else { - builder.append('"').append(variable).append('"'); + builder.append(variable).append('"'); } }