Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when connection to remote is invalid #315

Closed
FlorianSW opened this issue Jun 12, 2017 · 0 comments
Closed

App crashes when connection to remote is invalid #315

FlorianSW opened this issue Jun 12, 2017 · 0 comments

Comments

@FlorianSW
Copy link
Member

If the app cannot connect to the given remote url, it simply crashes with this stask trace:

06-12 20:07:34.198 20396-20943/org.openhab.habdroid E/NotificationSettings: Error loading notification settings: No route to host
06-12 20:07:34.202 20396-20943/org.openhab.habdroid E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                                      Process: org.openhab.habdroid, PID: 20396
                                                                      java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                          at android.os.AsyncTask$3.done(AsyncTask.java:318)
                                                                          at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                          at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                          at java.lang.Thread.run(Thread.java:761)
                                                                       Caused by: java.lang.IllegalStateException: protocol == null
                                                                          at okhttp3.Response$Builder.build(Response.java:428)
                                                                          at org.openhab.habdroid.util.MySyncHttpClient.method(MySyncHttpClient.java:67)
                                                                          at org.openhab.habdroid.util.MySyncHttpClient.method(MySyncHttpClient.java:28)
                                                                          at org.openhab.habdroid.util.MyHttpClient.get(MyHttpClient.java:70)
                                                                          at org.openhab.habdroid.core.notifications.NotificationSettings.loadSettings(NotificationSettings.java:70)
                                                                          at org.openhab.habdroid.core.notifications.NotificationSettings.getSenderId(NotificationSettings.java:81)
                                                                          at org.openhab.habdroid.core.notifications.GoogleCloudMessageConnector.register(GoogleCloudMessageConnector.java:39)
                                                                          at org.openhab.habdroid.ui.OpenHABMainActivity$13.doInBackground(OpenHABMainActivity.java:1196)
                                                                          at org.openhab.habdroid.ui.OpenHABMainActivity$13.doInBackground(OpenHABMainActivity.java:1189)
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                          at java.lang.Thread.run(Thread.java:761) 
FlorianSW added a commit to FlorianSW/openhab.android that referenced this issue Jun 12, 2017
If the connection to the remote host could not be established, the app
creates a fake response with the error message and status code 500 for the
notification settings sync hhtp request. However, until now, the creation
of this Fake response failed, as the Response builder requires some data,
which was not given so far.

This also refactors the MyHttpClient sslSetup method, which does not need
to get the whole context passed to it and therefore the constructors of
MyAsync and MySyncHttpClient does not need this neither. It now takes a
boolean argument, which indicates, if hostnames of a ssl cert should be
ignored or not.

Fixes openhab#315
digitaldan pushed a commit that referenced this issue Jun 30, 2017
* Fix crash if "No route to host"

If the connection to the remote host could not be established, the app
creates a fake response with the error message and status code 500 for the
notification settings sync hhtp request. However, until now, the creation
of this Fake response failed, as the Response builder requires some data,
which was not given so far.

This also refactors the MyHttpClient sslSetup method, which does not need
to get the whole context passed to it and therefore the constructors of
MyAsync and MySyncHttpClient does not need this neither. It now takes a
boolean argument, which indicates, if hostnames of a ssl cert should be
ignored or not.

Fixes #315

* Fix changed method signature

* Fix new method signature for Test

* Add more detailed information in error message (Exception class)

This also allows us to have a test case, which still checks that the
request failed for the correct reason but does not rely on the exact error
message anymore, which seems to be different in different circumstances.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants