Throw proper exceptions when an HTTP request fails