Some refactoring and handling of HTTP error situations.