Http 500 error and offline processing

14 views
Skip to first unread message

Rubén V

unread,
Jan 23, 2021, 10:44:04 PM1/23/21
to CodenameOne Discussions
Hi,

I have an app that saves vital information in a local database (within the mobile). I apply all the business rules to local data and if I have a data connection I send them to a server through the rest full API. The database is on an external server, but I have the app and the webservice in test mode on my computer. Simulate that I lost the data connection considering that the "getResponseCode" method would return the error 500 and allow me to continue, on the contrary, it shows me an error window with the options to retry and cancel. My intention is that the app continues to work in the event of any communication or server error. Should I put in a "try" statement to catch the error, or is there another way? Example method:

    public static void adicionaVisita(Visita v) {
        Response<String> r = VisitaService.adicion(v);
        if (r.getResponseCode() == 200) {
            procesaRegistro(v, MODO_ELIMINA);
            v.visitaId.set(Long.parseLong(r.getResponseData()));
            v.modoPendiente.set(0);
            procesaRegistro(v, MODO_ADICION);
        }
    }

Shai Almog

unread,
Jan 24, 2021, 9:28:48 PM1/24/21
to CodenameOne Discussions
Hi,
in your main class there's generic code that handles networking errors and shows an error dialog. Just comment out the portion that shows the dialog. Specifically:

addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if(err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
});

Rubén V

unread,
Jan 24, 2021, 10:29:11 PM1/24/21
to CodenameOne Discussions
Thanks
Reply all
Reply to author
Forward
0 new messages