On Fri, Jun 6, 2008 at 5:11 PM, mc <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> When an exception occurs in my application I want to ba able to set
> the response code and return a specific response body. I can set the
> response without a problem but Pylons seems to be overriding the
> response code and returns a 200 instead.
>
> Here's my code snippet:
>
> class MyController(BaseController)
> def index(self):
> result = {}
> try: # try-except
> result["result"] = func(*args, **kwargs)
> except (KeyError, ValueError), e:
> response.status = 400
> result["error"] = str(e)
> except Exception, e:
> response.status = 500
> result["error"] = str(e)
> finally:
> return result
>
> I've read through the pylons docs on the wiki, but I can only find
> references to an abort() method which sets the response code but
> doesn't allow me to set the body. Any suggestions or pointers where I
> can look for more information
I set up an access log in my base controller's .__call__ method, and
for some reason the errors are showing up as 200. So something
strange is happening to the status but I haven't figured out where.
It could be related to your problem.
The integer version of the status is in response.status_code, not
response.status. Maybe you need to set it there. In the development
version of Pylons it's in response.status_int due to the migration to
WebOb.
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---