General cleanup and restructuring of HTTP error handling. The new code separates IOExceptions from failed HTTP communications and allows handling of HTTP errors later in the code.