https://kotlinlang.org logo
#android
Title
# android
g

girafferson

07/19/2019, 4:49 PM
Hello, I am using the suspend in retrofit and when I make a call it immediately throws ConnectionException when there's no internet connection. My question is, shouldn't it be waiting for the timeout? I'm using timeout in httpclient and in an interceptor. Here is the error thrown: https://pastebin.com/QKLB34j8 The error says after 30000ms but it definitely does not wait that long. Any help very much appreciated!
I think it has more to do with OkHttp ignoring my timeout but I'm really unsure. Maybe timeout doesn't include wifi manually disconnecting?
If it helps I am using a proxy. When I'm not using a proxy, my app fails silently. I'm assuming that it's failing because it can't connect it's just not showing the error because something to do with me using coroutines
d

Dominaezzz

07/19/2019, 6:32 PM
Timeout? When there's no connection to wait for?
g

girafferson

07/19/2019, 6:48 PM
I'm not sure what you mean. If the network configuration is changing states, it should wait to connect. From what I can tell my timeout doesn't work because I can't apply a DNS timeout so it fails immediately. I tried adding callTimeout but that's not working either. If I need to do something like observe network connection that's fine I just don't see anything about that on any stack overflow posts
a

Al Warren

07/19/2019, 7:32 PM
You're going to have to do a manual check before making your request. I don't think there's a clean way around that. I use a sealed class that represents anticipated failures. Then I use that to semantically describe a failure that gets returned via a monad to the caller. It eventually makes it's way back to the view which does a type check for failure or expected result.
r

Ryan Mentley

07/19/2019, 8:06 PM
Looks like the error message might be wrong, but otherwise, that's exactly expected behavior for how connection timeouts generally work. If it affirmatively fails (for instance, because you don't have a network connection, or because the proxy refuses it, or because the destination server refuses it), it won't wait - the connection has already failed, and needs to be retried from scratch.
👍 1
16 Views