Networking errors and time-outs
When dealing with networks, there is one rule you have to keep in mind. That rule is: assume that the other party is not answering your call.
Servers go down. Connections can drop. Networks are unreachable. There are a whole lot of issues that will (not might!) happen.
You must use defensive coding to ensure it doesn’t impact your code too much. Of course, if you rely on an external machine to get the data you need, and that machine is not available, you have a problem. But maybe you can get around it. Perhaps you can cache older data. Or, you can retry if something goes wrong.
Let me help you with some strategies you can use to deal with hiccups in the network.
Using the HTTPClient wisely
The HTTPClient
class has some neat tricks to help you with making the use of it more stable. For instance, connection pooling comes free and out of the box in this handy class. And they built that connection pooling in a pretty clever way.