Skip to content

Commit

Permalink
Allow to pass a custom exception handler for the response.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Apr 23, 2016
1 parent 1b6f957 commit e621acf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CHANGES.rst
@@ -1,12 +1,13 @@
Changelog
=========

1.6.12 (unreleased)
-------------------
1.7.0 (unreleased)
------------------

New:

- *add item here*
- Allow to pass a custom exception handler for the response.
[jensens]

Fixes:

Expand Down
9 changes: 6 additions & 3 deletions plone/subrequest/__init__.py
Expand Up @@ -68,7 +68,7 @@ class IDisableCSRFProtection(Interface):
logger = getLogger('plone.subrequest')


def subrequest(url, root=None, stdout=None):
def subrequest(url, root=None, stdout=None, exception_handler=None):
assert url is not None, 'You must pass a url'
if isinstance(url, unicode):
url = url.encode('utf-8')
Expand Down Expand Up @@ -156,9 +156,12 @@ def subrequest(url, root=None, stdout=None):
response.setBody(result)
for key, value in request.response.cookies.items():
parent_request.response.cookies[key] = value
except Exception:
except Exception, e:
logger.exception('Error handling subrequest to {0}'.format(url))
response.exception()
if exception_handler is not None:
exception_handler(response, e)
else:
response.exception()
return response
finally:
if SAFE_WRITE_KEY in request.environ:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@
import os.path


version = '1.6.12.dev0'
version = '1.7.0.dev0'

setup(
name='plone.subrequest',
Expand Down

1 comment on commit e621acf

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jensens Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-plone.subrequest/16/violations

plone/subrequest/__init__.py:71:1: C901 'subrequest' is too complex (22)
plone/subrequest/subresponse.py:22:12: P002 found "hasattr", consider replacing it
plone/subrequest/subresponse.py:23:16: P002 found "hasattr", consider replacing it
plone/subrequest/subresponse.py:24:12: P002 found "hasattr", consider replacing it
plone/subrequest/subresponse.py:50:16: P002 found "hasattr", consider replacing it

Follow these instructions to reproduce it locally.

Please sign in to comment.