Skip to content

Commit 6208c0d

Browse files
authored
Fix variables serialization bug in TestProxyRecordPolicy (Azure#37075)
1 parent ef953f7 commit 6208c0d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,21 @@ private void setDefaultRecordingOptions() {
104104
/**
105105
* Stops recording of test traffic.
106106
* @param variables A list of random variables generated during the test which is saved in the recording.
107+
* @throws RuntimeException If the test proxy returns an error while stopping recording.
107108
*/
108109
public void stopRecording(Queue<String> variables) {
109110
HttpRequest request = new HttpRequest(HttpMethod.POST, proxyUrl + "/record/stop")
110111
.setHeader(HttpHeaderName.CONTENT_TYPE, "application/json")
111112
.setHeader(X_RECORDING_ID, xRecordingId)
112113
.setBody(serializeVariables(variables));
113-
client.sendSync(request, Context.NONE).close();
114+
115+
try (HttpResponse response = client.sendSync(request, Context.NONE)) {
116+
checkForTestProxyErrors(response);
117+
118+
if (response.getStatusCode() == 400) {
119+
throw new RuntimeException(response.getBodyAsBinaryData().toString());
120+
}
121+
}
114122
}
115123

116124
/**
@@ -138,7 +146,7 @@ private String serializeVariables(Queue<String> variables) {
138146
if (variable == null) {
139147
builder.append("null");
140148
} else {
141-
builder.append('"').append(variable).append('"');
149+
builder.append(variable).append('"');
142150
}
143151
}
144152

0 commit comments

Comments
 (0)