From d25bda49eec5195881213bfbcc377fbe342b9128 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 20 Oct 2022 14:42:30 -0700 Subject: [PATCH] capture details when returned --- .../ai/textanalytics/_response_handlers.py | 1 + ...ad_model_version_error_multiple_tasks.json | 25 ++++++++++++++----- .../tests/test_analyze.py | 3 ++- .../azure-ai-textanalytics/tests/testcase.py | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_response_handlers.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_response_handlers.py index 53eba08f7577..082bc4aaf041 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_response_handlers.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_response_handlers.py @@ -46,6 +46,7 @@ def __init__(self, odata_error): super().__init__( odata_error["error"]["innererror"] ) + self.details = odata_error["error"].get("details", []) except KeyError: super().__init__(odata_error) diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.pyTestAnalyzetest_bad_model_version_error_multiple_tasks.json b/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.pyTestAnalyzetest_bad_model_version_error_multiple_tasks.json index 3b4dc62f72f4..ede0b5924fc6 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.pyTestAnalyzetest_bad_model_version_error_multiple_tasks.json +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze.pyTestAnalyzetest_bad_model_version_error_multiple_tasks.json @@ -9,7 +9,7 @@ "Connection": "keep-alive", "Content-Length": "721", "Content-Type": "application/json", - "User-Agent": "azsdk-python-ai-textanalytics/5.2.0b5 Python/3.10.0 (Windows-10-10.0.22000-SP0)" + "User-Agent": "azsdk-python-ai-textanalytics/5.2.1 Python/3.10.0 (Windows-10-10.0.22621-SP0)" }, "RequestBody": { "analysisInput": { @@ -65,21 +65,34 @@ }, "StatusCode": 400, "ResponseHeaders": { - "apim-request-id": "6cad3063-1c60-446b-9e79-843ab6d57c58", + "apim-request-id": "d387e29c-6117-425a-9a2c-7feaaa23a753", "Content-Type": "application/json; charset=utf-8", - "Date": "Thu, 09 Jun 2022 17:10:09 GMT", + "Date": "Thu, 20 Oct 2022 21:31:18 GMT", + "Server": "istio-envoy", "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", "Transfer-Encoding": "chunked", "X-Content-Type-Options": "nosniff", - "x-envoy-upstream-service-time": "5" + "x-envoy-upstream-service-time": "137", + "x-http2-stream-id": "3", + "x-ms-region": "East US" }, "ResponseBody": { "error": { "code": "InvalidRequest", - "message": "Invalid parameter in request", + "details": [ + { + "code": "InvalidRequest", + "message": "Invalid Request.", + "innererror": { + "code": "InvalidParameterValue", + "message": "Job task parameter value \u0027bad\u0027 is not supported for model-version parameter for job task type PersonallyIdentifiableInformation. Supported values latest, 2020-07-01, 2021-01-15." + } + } + ], + "message": "Invalid Request.", "innererror": { "code": "InvalidParameterValue", - "message": "Job task parameter value bad is not supported for model-version parameter for job task type KeyPhraseExtraction. Supported values latest,2019-10-01,2020-07-01,2021-05-01." + "message": "Job task: \u0027PersonallyIdentifiableInformation-2\u0027 failed with validation errors: [\u0027Invalid parameter in request\u0027]" } } } diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py index ecdca12071d5..ea27aa4ffaab 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py @@ -548,7 +548,7 @@ def test_invalid_language_hint_method(self, client): def test_bad_model_version_error_multiple_tasks(self, client): docs = [{"id": "1", "language": "en", "text": "I did not like the hotel we stayed at."}] - with pytest.raises(HttpResponseError): + with pytest.raises(HttpResponseError) as e: res = client.begin_analyze_actions( docs, actions=[ @@ -560,6 +560,7 @@ def test_bad_model_version_error_multiple_tasks(self, client): ], polling_interval=self._interval(), ).result() + assert e.value.error.details @TextAnalyticsPreparer() @TextAnalyticsClientPreparer() diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py b/sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py index d05d5ea620e1..9acffe8cb336 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py @@ -28,7 +28,7 @@ def is_public_cloud(): TextAnalyticsPreparer = functools.partial( PowerShellPreparer, 'textanalytics', - textanalytics_test_endpoint="https://fakeendpoint.cognitiveservices.azure.com", + textanalytics_test_endpoint="https://fakeendpoint.cognitiveservices.azure.com/", textanalytics_test_api_key="fakeZmFrZV9hY29jdW50X2tleQ==", )