On Mar 21, 2:11 pm, Michael Merickel <
mmeri...@gmail.com> wrote:
> The only way a NewResponse subscriber would be invoked *after* an exception
> occured is if you are handling the exception in an exception view. If
> that's the case, then you are rendering a new view and as part of the
> rendering, NewResponse will be invoked, and request.exception will be the
> exception.
Right.
My point is that if you don't use an Exception View, you don't seem to
have the ability to track your exceptions
@view_config(route_name="hello_world",renderer='hello_world.mako')
def hello_world():
#return {'project':'example'}
raise ValueError('example')
If I create an Exception View with "context=ValueError" , I'm able to
see in a NewResponse event that request.exception=ValueError
If I don't use an Exception View , then NewReponse does have a
request.exception attribute -- but it is set to None. So I know that
an Exception happened (in general)- and I can do some amount of
processing based on that, but I don't know what exception occurred or
where.
If the raised exception were stashed onto the event object, you could
quickly and easily have an event subscriber that handles all
exceptions.
> > from sqlalchemy.exc import OperationalError as
> > SqlAlchemyOperationalError
>
> > @view_config(context=SqlAlchemyOperationalError)
> > def failed_sqlalchemy(exception , request):
> > """do whatever here"
> > pass
>
> This is an actual view, so you need to return a response object, or a dict
> usable by a configured renderer.
yep, i knew that. thanks!