fix: workaround error when 'fanstatic.needed' missing from environ
what i've seen in the wild seems to be caused by a crawler trying to fetch non-minified JS files, when the fanstatic resource library only includes minified JS files. still not sure why that would cause the specific error but oh well, this hopefully "solves" for now
This commit is contained in:
parent
c667f1ab7e
commit
75b8de7ce3
2 changed files with 26 additions and 4 deletions
|
|
@ -70,8 +70,16 @@ class WebHandler(GenericHandler):
|
||||||
url = self.config.get("wuttaweb.favicon_url")
|
url = self.config.get("wuttaweb.favicon_url")
|
||||||
if url:
|
if url:
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
# nb. in rare circumstances i have received unhandled error email,
|
||||||
|
# which somehow was triggered by 'fanstatic.needed' being missing
|
||||||
|
# from the environ. not sure why that would happen, but it seems
|
||||||
|
# safe to ignore when it does - favicon is not *that* important.
|
||||||
|
if "fanstatic.needed" in request.environ:
|
||||||
return self.get_fanstatic_url(request, static.favicon)
|
return self.get_fanstatic_url(request, static.favicon)
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
def get_header_logo_url(self, request):
|
def get_header_logo_url(self, request):
|
||||||
"""
|
"""
|
||||||
Returns the canonical app header image URL.
|
Returns the canonical app header image URL.
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,18 @@ class TestWebHandler(WebTestCase):
|
||||||
self.assertEqual(url, "/fanstatic/wuttaweb_img/logo.png")
|
self.assertEqual(url, "/fanstatic/wuttaweb_img/logo.png")
|
||||||
|
|
||||||
# what about a subpath
|
# what about a subpath
|
||||||
self.request.script_name = "/testing"
|
with patch.object(self.request, "script_name", new="/testing"):
|
||||||
url = handler.get_fanstatic_url(self.request, static.logo)
|
url = handler.get_fanstatic_url(self.request, static.logo)
|
||||||
self.assertEqual(url, "/testing/fanstatic/wuttaweb_img/logo.png")
|
self.assertEqual(url, "/testing/fanstatic/wuttaweb_img/logo.png")
|
||||||
|
|
||||||
|
# error if environ missing config/data
|
||||||
|
environ = dict(self.request.environ)
|
||||||
|
del environ["fanstatic.needed"]
|
||||||
|
with patch.object(self.request, "environ", new=environ):
|
||||||
|
self.assertRaises(
|
||||||
|
KeyError, handler.get_fanstatic_url, self.request, static.logo
|
||||||
|
)
|
||||||
|
|
||||||
def test_get_favicon_url(self):
|
def test_get_favicon_url(self):
|
||||||
handler = self.make_handler()
|
handler = self.make_handler()
|
||||||
|
|
||||||
|
|
@ -45,6 +53,12 @@ class TestWebHandler(WebTestCase):
|
||||||
url = handler.get_favicon_url(self.request)
|
url = handler.get_favicon_url(self.request)
|
||||||
self.assertEqual(url, "/fanstatic/wuttaweb_img/favicon.ico")
|
self.assertEqual(url, "/fanstatic/wuttaweb_img/favicon.ico")
|
||||||
|
|
||||||
|
# returns empty if environ missing config/data
|
||||||
|
environ = dict(self.request.environ)
|
||||||
|
del environ["fanstatic.needed"]
|
||||||
|
with patch.object(self.request, "environ", new=environ):
|
||||||
|
self.assertEqual(handler.get_favicon_url(self.request), "")
|
||||||
|
|
||||||
# config override
|
# config override
|
||||||
self.config.setdefault("wuttaweb.favicon_url", "/testing/other.ico")
|
self.config.setdefault("wuttaweb.favicon_url", "/testing/other.ico")
|
||||||
url = handler.get_favicon_url(self.request)
|
url = handler.get_favicon_url(self.request)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue