|
20 | 20 | import pytest
|
21 | 21 | import subprocess
|
22 | 22 |
|
23 |
| -from azure.core.exceptions import ResourceNotFoundError |
| 23 | +from azure.core.exceptions import HttpResponseError, ResourceNotFoundError |
24 | 24 | from azure.core.pipeline.policies import ContentDecodePolicy
|
25 | 25 | # the functions we patch
|
26 | 26 | from azure.core.pipeline.transport import RequestsTransport
|
@@ -86,16 +86,24 @@ def start_record_or_playback(test_id):
|
86 | 86 | RECORDING_START_URL,
|
87 | 87 | headers={"x-recording-file": test_id, "x-recording-sha": current_sha},
|
88 | 88 | )
|
| 89 | + if result.status_code != 200: |
| 90 | + message = six.ensure_str(result._content) |
| 91 | + raise HttpResponseError(message=message) |
89 | 92 | recording_id = result.headers["x-recording-id"]
|
| 93 | + |
90 | 94 | else:
|
91 | 95 | result = requests.post(
|
92 | 96 | PLAYBACK_START_URL,
|
93 | 97 | headers={"x-recording-file": test_id, "x-recording-sha": current_sha},
|
94 | 98 | )
|
| 99 | + if result.status_code != 200: |
| 100 | + message = six.ensure_str(result._content) |
| 101 | + raise HttpResponseError(message=message) |
| 102 | + |
95 | 103 | try:
|
96 | 104 | 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) |
99 | 107 | if result.text:
|
100 | 108 | try:
|
101 | 109 | variables = result.json()
|
@@ -208,8 +216,9 @@ def combined_call(*args, **kwargs):
|
208 | 216 | test_output = test_func(*args, **trimmed_kwargs)
|
209 | 217 | except ResourceNotFoundError as error:
|
210 | 218 | 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) |
213 | 222 | finally:
|
214 | 223 | RequestsTransport.send = original_transport_func
|
215 | 224 | stop_record_or_playback(test_id, recording_id, test_output)
|
|
0 commit comments