Miscellaneous

Error handling


Note: This feature is available only in Android SDK and iOS SDK.

ApiError is an object for error handling. It’s designed to help you handle errors within your application. It provides details about failures in communication with the Synerise API.

This error is normally returned from the SDK methods that communicate with the Synerise API.

Properties

Property Method
Throwable apiError.getThrowable()
Stacktrace apiError.printStackTrace()
Type apiError.getErrorType()
HTTP code apiError.getHttpErrorCategory()
Body apiError.getErrorBody()

Throwable

Returns the original Throwable instance. It may be null if ApiError was instantiated with the ApiError(Response) constructor.

Stacktrace

Prints the stack trace of the original Throwable instance.

Type

ErrorType.HTTP_ERROR is returned when a request is executed, but something else goes wrong and an error code is returned (for example, 403).
ErrorType.NETWORK_ERROR is returned when a request failed to execute (for example, due to no Internet connection).
ErrorType.UNKNOWN is returned when an unknown error occurs (for example, no response from the server when expected).

HTTP code

Returns the HTTP status code. If the request failed to execute (for example, due to no Internet connection), this value will be -1.

HTTP error category

Returns the mapped response’s HTTP code (for example, HTTP 400 code will be mapped to HttpErrorCategory.BAD_REQUEST, or 403 to HttpErrorCategory.FORBIDDEN).

Body

Returns the ApiErrorBody parsed from the error’s response body. May be null if error type is different than ErrorType.HTTP_ERROR.

Sample

See the following code samples for reading errors:

private void showAlertError(ApiError apiError) {
    ApiErrorBody errorBody = apiError.getErrorBody();
    int httpCode = apiError.getHttpCode();
    // create AlertDialog with icon and title
    AlertDialog.Builder dialog = new AlertDialog.Builder(this).setIcon(R.drawable.sygnet_synerise);
    if (httpCode != ApiError.UNKNOWN_CODE) {
        dialog.setTitle(String.valueOf(httpCode));
    } else {
        dialog.setTitle(R.string.default_error);
    }
    // append all available messages from API
    if (errorBody != null) {
        List<ApiErrorCause> errorCauses = errorBody.getErrorCauses();
        StringBuilder message = new StringBuilder(errorBody.getMessage());
        if (!errorCauses.isEmpty())
            for (ApiErrorCause errorCause : errorCauses)
                message.append("\n").append(errorCause.getCode()).append(": ").append(errorCause.getMessage());
        dialog.setMessage(message.toString());
    // if there is no available messages, set default one
    } else {
        switch (apiError.getErrorType()) {
            case HTTP_ERROR:
                if (apiError.getHttpErrorCategory() == UNAUTHORIZED) {
                    dialog.setMessage(getString(R.string.error_unauthorized));
                } else {
                    dialog.setMessage(getString(R.string.error_http));
                }
                break;
            case NETWORK_ERROR:
                dialog.setMessage(getString(R.string.error_network));
                break;
            default:
                dialog.setMessage(getString(R.string.error_default));
        }
    }
    // show dialog
    dialog.show();
}

Crash handling


Crash handler allows you to detect mobile app users whose mobile applications crashed. This information is saved on the activity list of a mobile app user in the Profiles module in the form of an event.
The crash is connected with a customer. Using the data from our crash handler, you can send a personalized apology when the application crashes.

You can enable crash handling for Synerise SDK by using an SDK method (Android and iOS) or during initialization by using a builder method (React Native).

When it is enabled, the Synerise SDK passes info about an application crash in the form of a dedicated event to the backend (client.applicationCrashed is the action parameter of those events).

See sample codes below:

Synerise.crashHandlingEnabled(true);

Cache Manager


Note: This feature is available only in Android and iOS SDK.

Cache Manager provides you with an easy-to-use option to retrieve cached data if communication problems with the backend occur. If a request fails, you can obtain the cached data.

Currently, our Cache Manager supports:

Model Description
GetAccountInformation Caching after a successful Client.getAccount() response.

See the following code examples for accessing the cache:

YourClass cachedModel = (YourClass) CacheManager.getInstance().get(YourClass.class);
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker