Skip to content

Commit 2a8baab

Browse files
authored
[Test Proxy] Improve error handling (Azure#22452)
1 parent 78a7ea3 commit 2a8baab

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

tools/azure-sdk-tools/devtools_testutils/aio/proxy_testcase_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ async def combined_call(*args, **kwargs):
7979
test_output = await test_func(*args, **trimmed_kwargs)
8080
except ResourceNotFoundError as error:
8181
error_body = ContentDecodePolicy.deserialize_from_http_generics(error.response)
82-
error_with_message = ResourceNotFoundError(message=error_body["Message"], response=error.response)
83-
raise error_with_message
82+
message = error_body.get("message") or error_body.get("Message")
83+
error_with_message = ResourceNotFoundError(message=message, response=error.response)
84+
raise error_with_message from error
8485
finally:
8586
AioHttpTransport.send = original_transport_func
8687
stop_record_or_playback(test_id, recording_id, test_output)

tools/azure-sdk-tools/devtools_testutils/proxy_testcase.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import pytest
2121
import subprocess
2222

23-
from azure.core.exceptions import ResourceNotFoundError
23+
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
2424
from azure.core.pipeline.policies import ContentDecodePolicy
2525
# the functions we patch
2626
from azure.core.pipeline.transport import RequestsTransport
@@ -86,16 +86,24 @@ def start_record_or_playback(test_id):
8686
RECORDING_START_URL,
8787
headers={"x-recording-file": test_id, "x-recording-sha": current_sha},
8888
)
89+
if result.status_code != 200:
90+
message = six.ensure_str(result._content)
91+
raise HttpResponseError(message=message)
8992
recording_id = result.headers["x-recording-id"]
93+
9094
else:
9195
result = requests.post(
9296
PLAYBACK_START_URL,
9397
headers={"x-recording-file": test_id, "x-recording-sha": current_sha},
9498
)
99+
if result.status_code != 200:
100+
message = six.ensure_str(result._content)
101+
raise HttpResponseError(message=message)
102+
95103
try:
96104
recording_id = result.headers["x-recording-id"]
97-
except KeyError:
98-
raise ValueError("No recording file found for {}".format(test_id))
105+
except KeyError as ex:
106+
six.raise_from(ValueError("No recording file found for {}".format(test_id)), ex)
99107
if result.text:
100108
try:
101109
variables = result.json()
@@ -208,8 +216,9 @@ def combined_call(*args, **kwargs):
208216
test_output = test_func(*args, **trimmed_kwargs)
209217
except ResourceNotFoundError as error:
210218
error_body = ContentDecodePolicy.deserialize_from_http_generics(error.response)
211-
error_with_message = ResourceNotFoundError(message=error_body["Message"], response=error.response)
212-
raise error_with_message
219+
message = error_body.get("message") or error_body.get("Message")
220+
error_with_message = ResourceNotFoundError(message=message, response=error.response)
221+
six.raise_from(error_with_message, error)
213222
finally:
214223
RequestsTransport.send = original_transport_func
215224
stop_record_or_playback(test_id, recording_id, test_output)

0 commit comments

Comments
 (0)