Hello, I am using the suspend in retrofit and when...
# android
g
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
Timeout? When there's no connection to wait for?
g
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
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
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