R
R
Roman Chetverikov2020-10-03 18:46:11
Exceptions
Roman Chetverikov, 2020-10-03 18:46:11

How to notify about request/loading data error from Kotlin server?

Good day!
I am new to programming and in the process of developing an application I encountered the following problem:
There is an application written in Kotlin that makes a request to the server using the Retrofit2 library.
I need to implement a notification to the user when the connection is broken, the server fails, etc.
A notification tied simply to checking the Internet connection does not roll.
What I have already tried:
- I tried to catch and handle exceptions from the Call method through try / cath, but nothing comes out. if I understand correctly, this is due to the fact that the Retrofit2 library itself correctly handles exceptions related to connection loss, a falling server, etc.
- another option was that, logically, it is necessary to track whether the correct data came from the server or not, and on the basis of this, already notify the user. I tried to hook on the presence of data in the CurrentDataWeather, but also so far without success.
- there was also an option to use the check for the correctness of the received data using response.isSuccessful, but even without an Internet connection, isSuccessful returns true.

Please help with advice. Where to dig?
Thanks a lot!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question