Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise generic errors (catch all InternalError) when using WSGI #280

Merged
merged 10 commits into from
May 18, 2018
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Bugfixes
- Accept bytes and text as cookie value.
(`#263 <https://github.com/zopefoundation/Zope/pull/263>`_)

- always raise InternalError when using WSGI
(`#280 <https://github.com/zopefoundation/Zope/pull/280>`)


4.0b4 (2018-04-23)
------------------
Expand Down
11 changes: 7 additions & 4 deletions src/Testing/tests/test_testbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ def test_handle_errors_true(self):
self.folder._setObject('stub', ExceptionStub())
browser = Browser()

with self.assertRaises(HTTPError):
# HTTP errors only for WSGI
with self.assertRaises(ValueError):
browser.open('http://localhost/test_folder_1_/stub')
self.assertTrue(browser.headers['status'].startswith('500'))
self.assertIsNone(browser.contents)

with self.assertRaises(HTTPError):
browser.open('http://localhost/nothing-is-here')
Expand Down Expand Up @@ -165,8 +166,10 @@ def test_raise_http_errors_false(self):
browser = Browser()
browser.raiseHttpErrors = False

browser.open('http://localhost/test_folder_1_/stub')
self.assertTrue(browser.headers['status'].startswith('500'))
# HTTP errors only for WSGI
with self.assertRaises(ValueError):
browser.open('http://localhost/test_folder_1_/stub')
self.assertIsNone(browser.contents)

browser.open('http://localhost/nothing-is-here')
self.assertTrue(browser.headers['status'].startswith('404'))
Expand Down
10 changes: 9 additions & 1 deletion src/ZPublisher/httpexceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ def __call__(self, environ, start_response):
except HTTPException as exc:
return exc(environ, start_response)
except Exception as exc:
if self.debug_mode or environ.get('x-wsgiorg.throw_errors', False):
if self.debug_mode:
# In debug mode, let the web server log a real
# traceback
raise
elif environ.get('wsgi.errors') is not None:
# s. https://www.python.org/dev/peps/pep-0333/#id27
# Imho the catch all InternalError is the generic error case
# that should not be handled by the application but
# rather the WSGI server. This way the error along with
# the traceback ends up in the configured logs.
# 'wsgi.errors' must be defined according to PEP-0333
raise
return self.catch_all_response(exc)(environ, start_response)

def catch_all_response(self, exc):
Expand Down