-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix custom handling of refined HTTPError #924
Conversation
The documentation is not available anymore as the PR was closed or merged. |
try: | ||
_raise_for_status(r) | ||
except requests.exceptions.RequestException as e: | ||
try: | ||
message = e.response.json()["error"] | ||
except JSONDecodeError: | ||
message = e.response.text | ||
except AttributeError: | ||
message = e.args[0] | ||
raise type(e)(message) from e | ||
_raise_for_status(r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing issues. The existing fix would raise an error such as
huggingface_hub.utils._errors.RepositoryNotFoundError: 404 Client Error: Repository Not Found for url: https://huggingface.co/api/models/efwfwefw. If the repo is private, make sure you are authenticated. (Request ID: ktudRx2-3fp48WpTK6013)
but the e.response.text
is still Repository not found
. On the other hand with _raise_for_status(r)
there is no need anymore to capture the type of error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still to be figured would be this though
try:
model_info("efwfwefw")
except RepositoryNotFoundError as e:
print(e.response.text)
{"error":"Repository not found"}
but
model_info("efwfwefw")
correctly gives
huggingface_hub.utils._errors.RepositoryNotFoundError: 404 Client Error: Repository Not Found for url: https://huggingface.co/api/models/efwfwefw. If the repo is private, make sure you are authenticated. (Request ID: WJtGL2IulzooY9JLwHEBn)
Co-authored-by: Simon Brandeis <33657802+SBrandeis@users.noreply.github.com>
Co-authored-by: Julien Chaumond <julien@huggingface.co>
I did a second pass removing |
At the end of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very nice, thanks for working on it @osanseviero! Appreciate the work on the tests as well.
Co-authored-by: Lysandre Debut <lysandre.debut@reseau.eseo.fr>
Feel free to merge if you think this looks good 😄 quality is unrelated (#934) |
Thanks for your work, @osanseviero! |
As discussed internally, #878 introduced a backwards compatibility issue as it does not contain all the information from the original error (such as the
status_code
), which was being used in downstream libraries such as speechbrain.This PR changes the error handling to re-use the original error but with additional custom message. To avoid this situation happening again, also introducing some tests.