Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 2.39 KB

python_error_management.md

File metadata and controls

69 lines (52 loc) · 2.39 KB

Error management

Table of Contents

Overview

The Python Kortex API currently has only one mechanism to manage errors: surrounding the code block with a try/except statement pair and reacting to the exception.

Note that there are special cases explained at the end of this document.

Example

try:
	base_service.CreateUserProfile(Base_pb2.FullUserProfile())

except KClientException as ex:
	# Get error and sub error codes
	error_code = ex.get_error_code()
	sub_error_code = ex.get_error_sub_code()
	print("Error_code:{0} , Sub_error_code:{1} ".format(error_code, sub_error_code))
	print("Caught expected error: {0}".format(ex))

except KServerException as server_ex:
	# Do something...

except Exception:
	# Do something...

A KClientException is thrown when an error occurs on the API client side, just as a KServerException is thrown when the error occurs on the API server side.

A KClientException includes error code and sub error code information describing the exception. Here is a link to documentation explaining all of the error and sub error codes:

Special case

This section describes a case that doesn't follow the standard error management rules documented earlier in this document.

RouterClient

When a RouterClient object is instantiated a callback function (or lambda expression) can be specified. This function will be called if an exception is thrown during the process.

router = RouterClient(transport, lambda kException: print("Error detected: {}".format(kException)))