Skip to content

Commit

Permalink
Add egg:Zope2#httpexceptions WSGI middleware, refs #64.
Browse files Browse the repository at this point in the history
This serves the same purpose as `egg:paste#httpexceptions`, but
recognizes exceptions derived from `zExceptions.HTTPException`.
  • Loading branch information
hannosch committed Jul 22, 2016
1 parent 10a5689 commit 4f0f50c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Bugs Fixed
Features Added
++++++++++++++

- Add `egg:Zope2#httpexceptions` WSGI middleware.

- Update available HTTP response code, 302 is now called Found.

- Add a new `runwsgi` script to serve PasteDeploy files.
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def _read_file(filename):
'paste.app_factory': [
'main=Zope2.Startup.run:make_wsgi_app',
],
'paste.filter_app_factory': [
'httpexceptions=Zope2.Startup.httpexceptions:main',
],
'console_scripts': [
'mkzopeinstance=Zope2.utilities.mkzopeinstance:main',
'runwsgi=Zope2.Startup.serve:main',
Expand Down
18 changes: 18 additions & 0 deletions src/Zope2/Startup/httpexceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from zExceptions import HTTPException


class HTTPExceptionHandler(object):

def __init__(self, application):
self.application = application

def __call__(self, environ, start_response):
environ['Zope2.httpexceptions'] = self
try:
return self.application(environ, start_response)
except HTTPException as exc:
return exc(environ, start_response)


def main(app, global_conf=None):
return HTTPExceptionHandler(app)
2 changes: 1 addition & 1 deletion src/Zope2/utilities/skel/etc/zope.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ zope_conf = %(here)s/wsgi.conf

[pipeline:main]
pipeline =
egg:paste#httpexceptions
egg:Zope2#httpexceptions
egg:repoze.retry#retry
egg:repoze.tm2#tm
zope
Expand Down

0 comments on commit 4f0f50c

Please sign in to comment.