diff --git a/sopel/modules/isup.py b/sopel/modules/isup.py index afb6049b17..f2f1bfe8a5 100644 --- a/sopel/modules/isup.py +++ b/sopel/modules/isup.py @@ -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') diff --git a/test/modules/test_modules_isup.py b/test/modules/test_modules_isup.py index 2241c8ea80..5ec854d641 100644 --- a/test/modules/test_modules_isup.py +++ b/test/modules/test_modules_isup.py @@ -31,6 +31,7 @@ def test_get_site_url(site, expected): INVALID_SITE_URLS = ( + None, # missing '', # empty ' ', # empty once stripped 'steam://browsemedia', # invalid protocol