zopefoundation / zExceptions

zExceptions contains common exceptions used in Zope.
Other
0 stars 5 forks source link

HTTPException response not working with ZPublisher #10

Closed nazrulworld closed 3 years ago

nazrulworld commented 3 years ago

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

From plone BrowserView, replace WSGIRespone with zException.BadRequest

What I expect to happen:

I expect it should return normally with 400 with error message.

What actually happened:

File "/Users/nazrul/.cache/buildout/eggs/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/zpublisher.py", line 121, in applyTransformOnFailure
    applyTransformOnSuccess(event)
  File "/Users/nazrul/.cache/buildout/eggs/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/zpublisher.py", line 86, in applyTransformOnSuccess
    transformed = applyTransform(event.request)
  File "/Users/nazrul/.cache/buildout/eggs/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/zpublisher.py", line 67, in applyTransform
    body = response.getBody()
AttributeError: 'BadRequest' object has no attribute 'getBody'

What version of Python and Zope/Addons I am using:

Python: 3.7

dataflake commented 3 years ago

An exception is not a response object and it doesn't need to conform to the response object API. I'd consider that a bug in "plone.transformchain". It should check if it really has a response object before calling response APIs.

nazrulworld commented 3 years ago

Thanks a lot for the clarification. I thought this HTTPException will act like wsgi response when I look at this method https://github.com/zopefoundation/zExceptions/blob/master/src/zExceptions/__init__.py#L164 But fully agree on this a bug in "plone.transformchain"