> def mycacher(f): > client = > Client('*****************************************************************') > try: > d = f() > return d > except: > client.captureException() >
You probably want to re-raise the exception after calling client.captureException() -- otherwise, web2py will not do a database rollback, and nothing will be returned to the browser. Also, you might want to check whether the value returned by f() is a dictionary, and if so, return response.render(d) instead of just d -- that will allow you to capture exceptions in views as well as controllers. > With this i'm able to catch all the exceptions originated by a function in > the controller or by a function call inside a controller is handled with > this code, but the problems comes when a code inside the models (but > outside functions) is executed, for example, database definitions etc... > This is tricky because web2py runs all app code inside the restricted() function from gluon.restricted, and that function catches any errors and then raises a RestrictedError, which is then caught in gluon.main.wsgibase. Maybe at the top of each model file you could do: with client.capture_exceptions(): [all model code] Otherwise, I think you would have to hack the web2py framework code. The simplest option would be to insert a couple lines in gluon.main.wsgibase to call client.captureException() where the RestrictedError is caught. Alternatively, you could probably alter or monkey patch the RestrictedError class in gluon.restricted. Also, I'm not too familiar with Sentry, but perhaps rather than using client.captureException, you could instead use client.captureMessage. In that case, you could create a special web2py error handler and send the appropriate message to Sentry based on the traceback, etc., which can be retrieved from the error ticket. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.