Here is the answer to your queries.
How can I extract the actual error HTTP status code from the exception?
You can find and map the respective error codes details from here.
What is the standard framework which Microsoft suggests handling exception messages where you may or may not get HTTP status codes (consider a common framework leveraging multiple Azure services of different categories). Thanks!
- In most of failed events, it shows some response code, in case it is a long-awaited or stuck job/operation, you can drill down into activity log of resource or log analytics workspace which is recording all intermittent or failed events from past.
- You can take a network trace for Virtual network cases to find failed events.
- We can add --verbose or --debug in CLI commands to get the full details
- We can use logging library in Python SDK to log the error message in clean way.
- We can also use try/catch block to find the error message.
for document in result:
print(f"Document ID: {document.id}")
print(f"Document status: {document.status}")
if document.status == "Succeeded":
print(f"Source document location: {document.source_document_url}")
print(f"Translated document location: {document.translated_document_url}")
print(f"Translated to language: {document.translated_to}\n")
elif document.error:
print(f"Error Code: {document.error.code}, Message: {document.error.message}\n")
else:
print("The document status is unknown or there is no status code. Please check in activitiy logs/log analytics workspace\n")
poller = client.begin_translation(source_url, target_url, self.translation_language, storage_type="File")
result = poller.result(timeout=120)
except HttpResponseError as e:
status_code = e.status_code
print(f"HTTP Status Code: {status_code}")
print(f"Error Message: {e.message}")
Hope it addresses your query.
Thank you.