Skip to content

Commit

Permalink
Merge pull request #1950 from sopel-irc/isup-more-specific-errors
Browse files Browse the repository at this point in the history
isup: more specific errors
  • Loading branch information
dgw authored Nov 21, 2020
2 parents e9e327a + 0059659 commit b74329d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions sopel/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,33 @@ def handle_isup(bot, trigger, secure=True):
"""
try:
site = get_site_url(trigger.group(2))
response = requests.head(site, verify=secure)
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
response.raise_for_status()
response = response.headers
except ValueError as error:
bot.reply(str(error))
except requests.exceptions.SSLError:
bot.say(
'%s looks down from here. Try using %sisupinsecure'
% (site, bot.config.core.help_prefix))
except requests.RequestException:
bot.say('%s looks down from here.' % site)
else:
if response:
bot.say(site + ' looks fine to me.')
else:
bot.say(site + ' is down from here.')
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
.format(site, bot.config.core.help_prefix))
except requests.HTTPError:
bot.say(
'{} looks down to me (HTTP {} "{}").'
.format(site, response.status_code, response.reason))
except requests.ConnectTimeout:
bot.say(
'{} looks down to me (timed out while connecting).'
.format(site))
except requests.ReadTimeout:
bot.say(
'{} looks down to me (timed out waiting for reply).'
.format(site))
except requests.ConnectionError:
bot.say(
'{} looks down to me (connection error).'
.format(site))

# If no exception happened, the request succeeded.
bot.say(site + ' looks fine to me.')


@plugin.command('isupinsecure')
Expand Down
1 change: 1 addition & 0 deletions test/modules/test_modules_isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_get_site_url(site, expected):


INVALID_SITE_URLS = (
None, # missing
'', # empty
' ', # empty once stripped
'steam://browsemedia', # invalid protocol
Expand Down

0 comments on commit b74329d

Please sign in to comment.