Error handling

Android SDK has a wrapper called ApiError to help you handle errors within your app. These errors are normally returned back from our RESTful API methods that SDK implements.

When Throwable instance is passed to create ApiError wrapper, you can get following information:


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


Prints stack trace on original Throwable instance.


Returns http status code. If request failed to execute (e.g. due to no Internet connection), this value will be equal -1.


ErrorType.HTTP_ERROR is returned when request succeeded to execute, but something went wrong and error code is returned (e.g. 403).
ErrorType.NETWORK_ERROR is returned when request failed to execute (e.g. due to no Internet connection).
ErrorType.UNKNOWN is returned when unknown error occurred (e.g. no response form server when expected).


Returns mapped response’s http code (e.g. 400 http code will be mapped to HttpErrorCategory.BAD_REQUEST or 403 to HttpErrorCategory.FORBIDDEN).


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

Sample usage

When we receive an error, we can check if error is ApiError and then, there is possibility to get more information and get a list of all errors that occurred. Therefore, you can better integrate your own application with the Synerise SDK.

Below sample code shows way to handle API error:

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) {
    } else {
    // 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());
    // if there is no available messages, set default one
    } else {
        switch (apiError.getErrorType()) {
            case HTTP_ERROR:
                if (apiError.getHttpErrorCategory() == UNAUTHORIZED) {
                } else {
            case NETWORK_ERROR:
    // show dialog;

Obviously that’s just a suggestion how to implement errors exposed by SDK and you can always do it your way.

ApiErrorBody provides attributes like error, message, path, status and list of causes errors.
ApiErrorCause provides attributes like field, code, message, rejectedValue.


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.



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