Skip to content

Commit

Permalink
Merge pull request #2235 from Exirel/isup-reply-error-message-value-e…
Browse files Browse the repository at this point in the history
…rror

isup: catch up errors from get site and from requests differently
  • Loading branch information
dgw authored Jan 7, 2022
2 parents d36a19d + 96d37e5 commit 787baa6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ xmltodict==0.12
pytz
praw>=4.0.0,<6.0.0
geoip2>=4.0,<5.0
requests>=2.0.0,<3.0.0
requests>=2.24.0,<3.0.0
dnspython<3.0
sqlalchemy>=1.4,<1.5
9 changes: 7 additions & 2 deletions sopel/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ def handle_isup(bot, trigger, secure=True):
"""
try:
site = get_site_url(trigger.group(2))
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
except ValueError as error:
bot.reply(str(error))
return

try:
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
except requests.exceptions.SSLError:
bot.say(
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
Expand All @@ -83,6 +86,8 @@ def handle_isup(bot, trigger, secure=True):
bot.say(
'{} looks down to me (connection error).'
.format(site))
except ValueError:
bot.reply('"{}" is not a valid URL.'.format(site))
else:
# If no exception happened, the request must have succeeded.
bot.say(site + ' looks fine to me.')
Expand Down
4 changes: 2 additions & 2 deletions test/modules/test_modules_isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock):
"""Test URL that can't be parsed."""
requests_mock.head(
'http://.foo',
exc=ValueError("Failed to parse: '.foo', label empty or too long"),
exc=ValueError("Invalid URL"),
)

irc.pm(user, '.isup .foo')

assert len(bot.backend.message_sent) == 1, (
'.isup command should output exactly one line')
assert bot.backend.message_sent == rawlist(
'PRIVMSG User :User: Failed to parse: \'.foo\', label empty or too long'
'PRIVMSG User :User: "http://.foo" is not a valid URL.'
)


Expand Down

0 comments on commit 787baa6

Please sign in to comment.