Enfusion Script API
Loading...
Searching...
No Matches
BackendCallback Interface Reference

Object used as callback structure in which you will receive results of Backend requests exposed via ScriptAPIs. More...

Inheritance diagram for BackendCallback:
Managed

Public Member Functions

proto external void SetOnSuccess (BackendCallbackFunc onSuccess)
 Sets function which will be invoked if request was successful.
 
proto external void SetOnError (BackendCallbackFunc onError)
 Sets function which will be invoked if request failed due to some error.
 
proto external ERestResult GetRestResult ()
 Returns result code from RestApi.
 
proto external EBackendRequest GetBackendRequest ()
 Returns type of request that invoked callback.
 
proto external EBackendError GetBackendError ()
 Returns backend error of failed request.
 
proto external EApiCode GetApiCode ()
 Returns API code of the request which can represent specific reason why the request failed.
 
proto external HttpCode GetHttpCode ()
 Returns HTTP code result of the request.
 
proto external string GetErrorMessage ()
 Returns additional message provided by the backend to the request error.
 
proto external string GetErrorUID ()
 Returns UID of the request error.
 
proto external Managed GetResultData ()
 Returns weak reference to possible result data from request response if supported.
 
void OnSuccess (int code)
 OBSOLETE - WILL BE REMOVED! Use SetOnSuccess() to set callback function instead!
 
void OnError (int code, int restCode, int apiCode)
 OBSOLETE - WILL BE REMOVED! Use SetOnError() to set callback function instead!
 
void OnTimeout ()
 OBSOLETE - WILL BE REMOVED! Use SetOnError() to set callback function instead and check GetRestResult() == ERestResult.EREST_ERROR_TIMEOUT!
 
- Public Member Functions inherited from Managed
proto external ref Managed Clone ()
 Return shallow copy of object, or null if it is not allowed (not public constructor)
 

Detailed Description

Object used as callback structure in which you will receive results of Backend requests exposed via ScriptAPIs.

For callback function you can use any function without arguments or with BackendCallback as the only argument. If BackendCallback was provided as the argument it will contain BackendCallback used for the request that invoked it. Allowed arguments of the function can be found in typedef of BackendCallbackFunc.

Warning
Callback has to be preserved until it receives response. If it is deleted before it finishes then request will be automatically killed. If callback is not stored as ref then it will be deleted after its execution finishes.
Note
Timeouts of native Backend requests should be generally considered and handled same as an error. But if required it can be differentiated via GetRestResult() == ERestResult.EREST_ERROR_TIMEOUT

Examples of callback functions:

// you can use function without arguments
void MyOnSuccessFunction()
{
// This code will be executed on successful request
}
// or add BackendCallback argument
void MyOnSuccessFunction(BackendCallback cb)
{
// This code will be executed on successful request
// you can access specific API code for special behavior
EApiCode apiCode = cb.GetApiCode();
// you can access HTTP result code as enum
HttpCode httpResultEnum = cb.GetHttpCode();
}
// use different function for error event
void MyOnErrorFunction(BackendCallback cb)
{
// This code will be executed if request failed
// you can access API code provided by backend in case of error
EApiCode apiCode = cb.GetApiCode();
// you can store HTTP code as int for codes undefined in HttpCode enum
int httpResultInt = cb.GetHttpCode();
}
EApiCode
Definition EApiCode.c:13
HttpCode
Common HTTP (result / error) codes Can be used in code as constant values to easier find use of speci...
Definition HttpCode.c:19
Object used as callback structure in which you will receive results of Backend requests exposed via S...
Definition BackendCallback.c:72
proto external EApiCode GetApiCode()
Returns API code of the request which can represent specific reason why the request failed.
proto external HttpCode GetHttpCode()
Returns HTTP code result of the request.

You have to set functions on the BackendCallback instance for them to be invoked:

m_MyCallback = new BackendCallback();
m_MyCallback.SetOnSuccess(MyOnSuccessFunction);
m_MyCallback.SetOnError(MyOnErrorFunction);

Member Function Documentation

◆ GetApiCode()

proto external EApiCode BackendCallback.GetApiCode ( )

Returns API code of the request which can represent specific reason why the request failed.

Some API codes when provided in OnSuccess can also direct what action should be taken next which means that not all API Codes represents errors.

◆ GetBackendError()

proto external EBackendError BackendCallback.GetBackendError ( )

Returns backend error of failed request.

◆ GetBackendRequest()

proto external EBackendRequest BackendCallback.GetBackendRequest ( )

Returns type of request that invoked callback.

◆ GetErrorMessage()

proto external string BackendCallback.GetErrorMessage ( )

Returns additional message provided by the backend to the request error.

Warning
This message is not localized and is more human readable technical message for unhandled errors. Localized error messages should be primarily based on API Codes.

◆ GetErrorUID()

proto external string BackendCallback.GetErrorUID ( )

Returns UID of the request error.

Note
This UID is technical information necessary to find relevant entry in backend side logs. Every service can have slightly different format so it is not specifically set which format this UID will have.

◆ GetHttpCode()

proto external HttpCode BackendCallback.GetHttpCode ( )

Returns HTTP code result of the request.

Note
For backend services we should not generally depend on HTTP code for specific errors or states and instead use API Codes. But is still good to show HTTP codes in case of errors for situations when we cannot depend on API Codes.

◆ GetRestResult()

proto external ERestResult BackendCallback.GetRestResult ( )

Returns result code from RestApi.

◆ GetResultData()

proto external Managed BackendCallback.GetResultData ( )

Returns weak reference to possible result data from request response if supported.

Otherwise returns null.

Warning
Request which used this callback must specify in documentation that it provides data through callback. In addition it must also specify of which type these data will be since it is necessary to cast them from Managed into type appropriate type.

◆ OnError()

void BackendCallback.OnError ( int code,
int restCode,
int apiCode )

OBSOLETE - WILL BE REMOVED! Use SetOnError() to set callback function instead!

◆ OnSuccess()

void BackendCallback.OnSuccess ( int code)

OBSOLETE - WILL BE REMOVED! Use SetOnSuccess() to set callback function instead!

◆ OnTimeout()

void BackendCallback.OnTimeout ( )

OBSOLETE - WILL BE REMOVED! Use SetOnError() to set callback function instead and check GetRestResult() == ERestResult.EREST_ERROR_TIMEOUT!

◆ SetOnError()

proto external void BackendCallback.SetOnError ( BackendCallbackFunc onError)

Sets function which will be invoked if request failed due to some error.

◆ SetOnSuccess()

proto external void BackendCallback.SetOnSuccess ( BackendCallbackFunc onSuccess)

Sets function which will be invoked if request was successful.


The documentation for this interface was generated from the following file: