How to catch the error in the get_analytics_conversation_details method in asynchronous mode?

Hi,

I would like to know how to catch the error in the get analytics conversation details method in asynchronous mode?

I tried to do it this way:

for conversation_id in convids:
try:

        AnalyticsApi.get_analytics_conversation_details(conversation_id, callback=callback_function)

 except ApiException as e:

      print(conversation_id, "ERROR:", e)

however when it fires the error always appears this way and I can't get it.

Exception in thread Thread-5 (__call_api):
Traceback (most recent call last):
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 343, in __call_api
response_data = self.request(method, url, query_params=query_params,
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 551, in request
return self.rest_client.GET(url,
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 202, in GET
return self.request("GET", url,
File "C:\Users\paulodo\AppData\Local\Programs\Python\Python310\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 197, in request
raise ApiException(http_resp=r)
PureCloudPlatformClientV2.rest.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '224', 'Connection': 'keep-alive', 'Date': 'Thu, 29 Sep 2022 19:07:09 GMT', 'ININ-Correlation-Id': '34412c52-0ab2-4831-af73-3711af175a8e', 'Strict-Transport-Security': 'max-age=600; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 65f7295ff05cf36f1a9f5c741069f294.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'GRU3-C2', 'X-Amz-Cf-Id': 'zCzYs8AZ_xqxkOqDhnB49UVcsazyy1pANbY7obd0E4HmvD7DXXTznQ=='})
HTTP response body: {"message":"Conversation 025c3def-c283-4489-ac46-5dd177e56414 was invalid or could not be found","code":"not.found","status":404,"messageParams":{},"contextId":"34412c52-0ab2-4831-af73-3711af175a8e","details":[],"errors":[]}

I would like to present the error more cleanly with just the message.

Regards,

Paulo

Hi,

The threading is a feature of Python's internal libraries and not the SDK and I believe the ApiException error message is just returned as a string in the SDK. You can turn off Python's Traceback by limiting it's depth. For example:

import sys
sys.tracebacklimit = 0

Following this approach, only the ApiException error message will be printed to your terminal. Please let me know if this solution works for you.

Thanks,

Mike

Hi Mike,

This solution solved my problem.

Thank you very much.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.