The exception is caught and shown by that code. What you're seeing is a limitation of modern Android/iOS devices both of which require HTTPS traffic by default. You can disable that but it might cause a problem moving forward in the app review process.
I would recommend adding a domain name and certificate to your server. There are free certificates you can use so this shouldn't be a problem. Alternatively for Android you can do this: https://stackoverflow.com/questions/57121953/usescleartexttraffic-not-permitted/57130188 For iOS you can do this: https://www.codenameone.com/blog/ios-http-urls.html On Saturday, January 2, 2021 at 12:53:31 PM UTC+2 [email protected] wrote: > 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/6ef7c226-3c35-48c8-b0a1-9d738d488e34n%40googlegroups.com.
