Error management

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.

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 ErrorCodes and SubErrorCodes to describe the exception.

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)))