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 triggering http post request if there is no internet connection #15

Open
thesnowgoose opened this issue May 14, 2017 · 4 comments

Comments

@thesnowgoose
Copy link

In Connection.java Class there is an AsyncTask called Task, there is where the POST request is triggered. There is a try-catch there that if the request fails it throws a new RuntimeException, but this exception is never handled and it causes my app to crash.

@CarlosMiguelCuevas
Copy link

good catch 👍

@thesnowgoose
Copy link
Author

It isn't even printing the stackTrace, I had to debug to find out what was going on, and was there I noticed Genymotion for any reason didn't have internet connection.

@danginirav
Copy link

I have the same problem. Have you found any work around? So, that app does not crash when there is no internet connection after triggering the request.

@pbertsch
Copy link

@richpeniche @picharras

2 things:

  1. You should not use DefaultHttpClient anymore:
  • Use openConnection, starting from API22 and removed in API 23 i think
  • You could use okHttp but Android already uses it internally
  • Use the Volley library, great for this small Class, does everything for you, you should take a look (I assume you don't because you don't want to depend on a lib)
  1. If you want to keep the Class on hand, than you should at least manage the Exception
  • Expand the Interface with a onRequestFailed() for example
  • Catch the Correct Exception and pass the error to the Listener so the developer can react, NEVER catch pure Exception - Bad habit.

I hope I could assist, let me know if you need anything else.

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

4 participants