ENH: Provide the error message from the HTTP server when return the HTTPError, #47242
ENH: Provide the error message from the HTTP server when return the HTTPError, #47242

Signed-off-by: Andrew Li <orcahmlee@gmail.com>

- [x] closes #47242 (Replace xxxx with the Github issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

> I would be -1 on this change. For `urllib.error.HTTPError`, the exception object contains more attributes than just the reason (code, reason, headers). So I think it's more sensible for the user to catch and log/handle as appropriate.

Hi @mroeschke , thanks for your advice.

I did some changes. I only appended the error message from the server and re-raise the `urllib.error.HTTPError`.

The user would see
```sh
urllib.error.HTTPError: HTTP Error 400: Bad Request, message from server: <MORE DETAILED MESSAGES> 
```
instead of 
```sh
urllib.error.HTTPError: HTTP Error 400: Bad Request
```

Also, the users are still able to catch the `urllib.error.HTTPError` if they want to access the attributes of the `HTTPError`.

Please give me some advice on this approach. > > I would be -1 on this change. For `urllib.error.HTTPError`, the exception object contains more attributes than just the reason (code, reason, headers). So I think it's more sensible for the user to catch and log/handle as appropriate.
> 
> Hi @mroeschke , thanks for your advice.
> 
> I did some changes. I only appended the error message from the server and re-raise the `urllib.error.HTTPError`.
> 
> The user would see
> 
> ```shell
> urllib.error.HTTPError: HTTP Error 400: Bad Request, message from server: <MORE DETAILED MESSAGES> 
> ```
> 
> instead of
> 
> ```shell
> urllib.error.HTTPError: HTTP Error 400: Bad Request
> ```
> 
> Also, the users are still able to catch the `urllib.error.HTTPError` if they want to access the attributes of the `HTTPError`.
> 
> Please give me some advice on this approach.

I still believe that this change is not significant enough to warrant a change in pandas. This exception is wholly provided by the Python stdlib and not necessarily pandas; therefore, HTTPError messaging should be improved in the stdlib.  > I still believe that this change is not significant enough to warrant a change in pandas. This exception is wholly provided by the Python stdlib and not necessarily pandas; therefore, HTTPError messaging should be improved in the stdlib.

OK, I see. Thanks again for your review.