SpiffyTitles: better error handling

This commit is contained in:
oddluck 2020-05-11 08:13:44 -04:00
parent e086f78679
commit 8fb4618d79

View File

@ -228,7 +228,12 @@ class SpiffyTitles(callbacks.Plugin):
(html, is_redirect) = self.get_source_by_url(url, channel)
if html:
title = self.get_title_from_html(html)
if title:
if not title:
log.error(
"SpiffyTitles: Unable to parse title from html response for %s"
% (url)
)
title = self.registryValue("badLinkText", channel=channel)
title_template = default_template.render(
title=title, redirect=is_redirect
)
@ -392,7 +397,10 @@ class SpiffyTitles(callbacks.Plugin):
title = None
soup = BeautifulSoup(html)
if soup:
try:
title = soup.title.string.strip()
except:
pass
if title:
return title
else:
@ -468,7 +476,7 @@ class SpiffyTitles(callbacks.Plugin):
log.error(
"SpiffyTitles HTTP response code %s" % (request.status_code,)
)
text = self.registryValue("badLinkText")
text = self.registryValue("badLinkText", channel=channel)
text = (
"<html><head><title>{0}</title>"
"</head><body></body></html>".format(text)