Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
I am confused with the onFailure method and onResponse Method.
I understand we have both of these methods although why are we using a try and catch block within the onReponse Method. Doesn't onResponse only get called if the message was successful meaning we should use the alertUserAboutError only in the onFailure method? I am sorry if this makes no sense I am just a little confused with these lines of code.
Other than that you have been an amazing teacher and I couldn't be more happier learning through tree house!
Ben DeitchTreehouse Teacher
Hi Aleksei! Whenever you make an HTTP call, if the call makes it to the server (i.e. you and the server are both connected to the internet), you'll get one of these response codes. However, only some of these codes indicate a successful response. Others represent something else (e.g. 404 means not found). So in order for a response to be successful, it needs to return a status code in the 200 range. And if we look at the documentation for 'isSuccessful' in OkHttp, that's exactly what we see.