From d78d12bbe44116c75d1deb802cc386fd12b993eb Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Mon, 30 Jan 2023 21:57:17 +0100 Subject: [PATCH] docs: extend example with new error reporting --- README.md | 12 ++++++++---- template/README.mustache | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 56c9d0e8..c3a52dc2 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,6 @@ Please follow the [installation procedure](#installation--usage) and then run th ```python import fingerprint_pro_server_api_sdk -from fingerprint_pro_server_api_sdk import Response -from fingerprint_pro_server_api_sdk.rest import ApiException # Configure API key authorization and region configuration = fingerprint_pro_server_api_sdk.Configuration(api_key="SECRET_API_KEY") @@ -101,7 +99,7 @@ Fetching visits using visitorId: ```python import fingerprint_pro_server_api_sdk from fingerprint_pro_server_api_sdk import Response -from fingerprint_pro_server_api_sdk.rest import ApiException +from fingerprint_pro_server_api_sdk.rest import ApiException, KnownApiException configuration = fingerprint_pro_server_api_sdk.Configuration(api_key="SECRET_API_KEY") api_instance = fingerprint_pro_server_api_sdk.FingerprintApi(configuration) @@ -115,6 +113,9 @@ limit = 10 # int | Limit scanned results (optional) try: api_response: Response = api_instance.get_visits(visitor_id, limit=2) print(api_response) +except KnownApiException as e: + structured_error = e.structured_error + print("Error: %s\n" % structured_error.error) except ApiException as e: print("Exception when calling DefaultApi->visitors_visitor_id_get: %s\n" % e) ``` @@ -123,7 +124,7 @@ Fetching events for requestId: ```python import fingerprint_pro_server_api_sdk from fingerprint_pro_server_api_sdk import EventResponse -from fingerprint_pro_server_api_sdk.rest import ApiException +from fingerprint_pro_server_api_sdk.rest import ApiException, KnownApiException configuration = fingerprint_pro_server_api_sdk.Configuration(api_key="SECRET_API_KEY") api_instance = fingerprint_pro_server_api_sdk.FingerprintApi(configuration) @@ -133,6 +134,9 @@ request_id = 'request_id_example' # str try: events_response: EventResponse = api_instance.get_event(request_id) +except KnownApiException as e: + structured_error = e.structured_error + print("Error code: %s. Error message: %s\n" % (structured_error.error.code, structured_error.error.message)) except ApiException as e: print("Exception when calling DefaultApi->get_event: %s\n" % e) ``` diff --git a/template/README.mustache b/template/README.mustache index 689c861f..403e242b 100644 --- a/template/README.mustache +++ b/template/README.mustache @@ -92,8 +92,6 @@ Please follow the [installation procedure](#installation--usage) and then run th ```python import {{packageName}} -from {{packageName}} import Response -from {{packageName}}.rest import ApiException # Configure API key authorization and region configuration = {{packageName}}.Configuration(api_key="SECRET_API_KEY") @@ -109,7 +107,7 @@ Fetching visits using visitorId: ```python import {{packageName}} from {{packageName}} import Response -from {{packageName}}.rest import ApiException +from {{packageName}}.rest import ApiException, KnownApiException configuration = {{packageName}}.Configuration(api_key="SECRET_API_KEY") api_instance = {{packageName}}.FingerprintApi(configuration) @@ -123,6 +121,9 @@ limit = 10 # int | Limit scanned results (optional) try: api_response: Response = api_instance.get_visits(visitor_id, limit=2) print(api_response) +except KnownApiException as e: + structured_error = e.structured_error + print("Error: %s\n" % structured_error.error) except ApiException as e: print("Exception when calling DefaultApi->visitors_visitor_id_get: %s\n" % e) ``` @@ -131,7 +132,7 @@ Fetching events for requestId: ```python import {{packageName}} from {{packageName}} import EventResponse -from {{packageName}}.rest import ApiException +from {{packageName}}.rest import ApiException, KnownApiException configuration = {{packageName}}.Configuration(api_key="SECRET_API_KEY") api_instance = {{packageName}}.FingerprintApi(configuration) @@ -141,6 +142,9 @@ request_id = 'request_id_example' # str try: events_response: EventResponse = api_instance.get_event(request_id) +except KnownApiException as e: + structured_error = e.structured_error + print("Error code: %s. Error message: %s\n" % (structured_error.error.code, structured_error.error.message)) except ApiException as e: print("Exception when calling DefaultApi->get_event: %s\n" % e) ```