Hi Amine, There are a couple posts on this:
https://www.codenameone.com/blog/rest-api-error-handling.html https://www.codenameone.com/blog/new-default-code.html This way you can implement retries, etc In my experience, you should have all bases covered if you implement onError onErrorCode(JSON/byte etc) And then check (and retry or whatever you want to do without a popup if true) resp.getResponseCode() != 200 resp.getResponseData() == null If you know the expected result of a JSON response it's useful to also check it isn't null as sometimes network exceptions can return a non-null response but a null response body Example: for a response that consists of {"result":"ok"} You can check ((String) resp.getResponseData().get("result")) == null A full JSON post implementation that retries automatically after waiting 1 second (and expects the above response format) would look like this public Response<Map> safeSyncRestPost(String url, String body) { Boolean[] error = {false}; RequestBuilder req = Rest.post(url) .onError(ee -> { error[0] = true; }, true); if(body != null) req.body(body); Response<Map> resp = req.header("Content-Type", "application/json").onErrorCodeJSON(err -> { error[0] = true; }) .getAsJsonMap(); if (resp.getResponseCode() != 200) { ;//log error optionally } else if (error[0]) { ;//log error optionally } else if (resp.getResponseData() == null) { ;//log error optionally } else if (((String) resp.getResponseData().get("result")) == null) { ;//log error optionally } else { return resp;//success } try { Thread.sleep(1000); } catch (InterruptedException ex) {} return safeSyncRestPost(url, body);//retry } On Sat, 2 Jan 2021 at 10:39, Amine <[email protected]> wrote: > Hi, > I have pop up showing exception even when catch it (try catch). How can i > prevent this pop up??? I use rest.post. > Pleasz help, > Kind regards, > > -- > You received this message because you are subscribed to the Google Groups > "CodenameOne Discussions" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/codenameone-discussions/fd58352c-8a25-465c-99db-89c04724a49co%40googlegroups.com > <https://groups.google.com/d/msgid/codenameone-discussions/fd58352c-8a25-465c-99db-89c04724a49co%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/CAG90yJ3oCyLsFnV9OHOMHKDzR7htNPh0jg_dEd1EAwVjzEb5Nw%40mail.gmail.com.
