I have this when(kotlin)
/switch case(java)
which gets java.net
exceptions for my requests. The problem is that it throws UnknownHostException
for two cases:
When I have no connection.
When I insert a broken url (that would be the equivalent to server completely unavailable).
How can I differentiate this two cases if they throw the same exception? Should I check the user's connection before every request?
when/try catch
is SocketTimeoutException -> {
//Server takes too long to respond
}
is UnknownHostException -> {
//No connection and broken url / no server at all
}
is HttpException -> {
//server error response
}
else -> {
//Any other case
}