Skip to main content

Error management

Errors that happen in the context of the SDK are wrapped in a type of exception: D2Error, with the following fields:

AttributeTypeOptionalDescription
errorComponentD2ErrorComponenttrueSource of the error: Database, SDK or Server.
errorCodeD2ErrorCodetrueSDK-defined unique error code.
errorDescriptionStringtrueDescription of the error in english (technical details, just for logs and debugging).
httpErrorCodeIntegerfalseIf caused by HTTP request, HTTP error code.
originalExceptionExceptionfalseOriginal Java Exception causing the error, if any.

Any operation requested to the SDK can throw an error.

  • For operations returning RxJava objects, the errors can be extracted in the following way:

    d2.userModule().logIn(username, password, url)
    .subscribe(
    user -> {},
    error -> {
    if (error instanceof D2Error) {
    D2Error d2Error = (D2Error) error;
    Log.e("LOGIN", d2Error.errorComponent() + " " + d2Error.httpErrorCode() + " " + d2Error.errorCode());
    }
    }
    );
  • For blocking operations, it is also possible to retrieve a D2Error. The errors can be extracted by caching them as shown in the following code snippet:

    try {
    d2.userModule().blockingLogIn(username, password, url);
    } catch (Exception e) {
    if (e.getCause() instanceof D2Error) {
    D2Error d2Error = (D2Error) e.getCause();
    Log.e("LOGIN", d2Error.errorComponent() + " " + d2Error.httpErrorCode() + " " + d2Error.errorCode());
    }
    }

D2Errors are persisted in the Database when they occur, so they can be analyzed afterwards and diagnose possible problems. They can be accessed through it's own repository:

d2.maintenanceModule().d2Errors()
.byD2ErrorComponent().eq(D2ErrorComponent.Server)
.get();

The SDK team is now working together with the core team in order to provide a full list of common error codes, but it's still a work in progress.