|
23 | 23 | from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
|
24 | 24 |
|
25 | 25 | from dapr.clients import DaprClient, DaprGrpcClient
|
| 26 | +from dapr.clients.exceptions import DaprInternalError |
26 | 27 | from dapr.clients.health import DaprHealth
|
27 | 28 | from dapr.clients.http.client import DaprHttpClient
|
28 | 29 | from dapr.conf import settings
|
@@ -139,3 +140,51 @@ def test_timeout_exception_thrown_when_timeout_reached(self):
|
139 | 140 | self.server.set_server_delay(1.5)
|
140 | 141 | with self.assertRaises(TimeoutError):
|
141 | 142 | new_client.invoke_method(self.app_id, self.method_name, '')
|
| 143 | + |
| 144 | + def test_notfound_json_body_exception_thrown_with_status_code_and_reason(self): |
| 145 | + self.server.set_response(b'{"error": "Not found"}', code=404) |
| 146 | + with self.assertRaises(DaprInternalError) as context: |
| 147 | + self.client.invoke_method(self.app_id, self.method_name, '') |
| 148 | + |
| 149 | + error_dict = context.exception.as_dict() |
| 150 | + self.assertEqual("HTTP status code: 404", error_dict.get('message')) |
| 151 | + self.assertEqual("UNKNOWN", error_dict.get('errorCode')) |
| 152 | + self.assertEqual(b'{"error": "Not found"}', error_dict.get('raw_response_bytes')) |
| 153 | + self.assertEqual(404, error_dict.get('status_code')) |
| 154 | + self.assertEqual('Not Found', error_dict.get('reason')) |
| 155 | + |
| 156 | + def test_notfound_no_body_exception_thrown_with_status_code_and_reason(self): |
| 157 | + self.server.set_response(b'', code=404) |
| 158 | + with self.assertRaises(DaprInternalError) as context: |
| 159 | + self.client.invoke_method(self.app_id, self.method_name, '') |
| 160 | + |
| 161 | + error_dict = context.exception.as_dict() |
| 162 | + self.assertEqual("HTTP status code: 404", error_dict.get('message')) |
| 163 | + self.assertEqual("ERR_DOES_NOT_EXIST", error_dict.get('errorCode')) |
| 164 | + self.assertEqual(None, error_dict.get('raw_response_bytes')) |
| 165 | + self.assertEqual(404, error_dict.get('status_code')) |
| 166 | + self.assertEqual('Not Found', error_dict.get('reason')) |
| 167 | + |
| 168 | + def test_notfound_no_json_body_exception_thrown_with_status_code_and_reason(self): |
| 169 | + self.server.set_response(b"Not found", code=404) |
| 170 | + with self.assertRaises(DaprInternalError) as context: |
| 171 | + self.client.invoke_method(self.app_id, self.method_name, '') |
| 172 | + |
| 173 | + error_dict = context.exception.as_dict() |
| 174 | + self.assertEqual("HTTP status code: 404", error_dict.get('message')) |
| 175 | + self.assertEqual("UNKNOWN", error_dict.get('errorCode')) |
| 176 | + self.assertEqual(b"Not found", error_dict.get('raw_response_bytes')) |
| 177 | + self.assertEqual(404, error_dict.get('status_code')) |
| 178 | + self.assertEqual('Not Found', error_dict.get('reason')) |
| 179 | + |
| 180 | + def test_notfound_json_body_w_message_exception_thrown_with_status_code_and_reason(self): |
| 181 | + self.server.set_response(b'{"message": "My message", "errorCode": "MY_ERROR_CODE"}', code=404) |
| 182 | + with self.assertRaises(DaprInternalError) as context: |
| 183 | + self.client.invoke_method(self.app_id, self.method_name, '') |
| 184 | + |
| 185 | + error_dict = context.exception.as_dict() |
| 186 | + self.assertEqual("My message", error_dict.get('message')) |
| 187 | + self.assertEqual("MY_ERROR_CODE", error_dict.get('errorCode')) |
| 188 | + self.assertEqual(b'{"message": "My message", "errorCode": "MY_ERROR_CODE"}', error_dict.get('raw_response_bytes')) |
| 189 | + self.assertEqual(404, error_dict.get('status_code')) |
| 190 | + self.assertEqual('Not Found', error_dict.get('reason')) |
0 commit comments