-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled exception when checking if URL exists #101 #102
Conversation
Handle exceptions raised from the use of `requests.exceptions`.
Default value is False. Moved raising the exception behind the parameter.
Please relate this PR to an existing issue, or open one. |
There should be one open already: #101. |
try: | ||
request = requests.get(url) | ||
except Exception as ue: | ||
if ue.__class__.__module__ == "requests.exceptions": |
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.
Just catch the exception you want to handle separately direclty.
try:
res = requests.get(url)
except requests.exceptions.RequestException:
warning("Exception when making a GET request: %s" % ue)
return False
else:
return request.status_code == 200
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.
Hum, but this does not cover all exceptions so nevermind.
Handle exceptions raised from the use of
requests.exceptions
.Implement warning and critical in the style of the original authors:
Warning is used for capturing the faulty request.
Critical is used to notify user that there is a problem.
I am still leaving the raise FileNotFoundError there as I wanted to make another request for turning this optional.