Přeskočit obsah
For the complete DHIS2 documentation index, see llms.txt.

Error management

Chyby, ke kterým dochází v kontextu SDK, jsou zabaleny v typu výjimky: D2Error, s následujícími poli:

Atribut Typ Volitelný Popis
errorComponent D2ErrorComponent true Zdroj chyby: Databáze, SDK nebo Server.
errorCode D2ErrorCode true SDK definovaný jedinečný kód chyby.
errorDescription Řetězec true Popis chyby v angličtině (technické podrobnosti, pouze pro protokoly a ladění).
httpErrorCode Celé číslo false Pokud je to způsobeno požadavkem HTTP, kód chyby HTTP.
originalException Výjimka false Původní výjimka Java způsobující chybu, pokud existuje.

Jakákoli operace požadovaná pro SDK může vyvolat chybu.

  • 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();

Tým SDK nyní pracuje společně s týmem jádra, aby poskytl úplný seznam běžných chybových kódů, ale práce stále probíhá.