Fix handling of exception http.client.IncompleteRead.
Reduce code duplication.

Make download error handling code into a decorator so that it can be
used on different urllib calls.