Hi,
I made another test, I tried the errorhandling as explained in cherrypy
by using exclusively cherrypy without tg, and guess what: it works! :-)
but when I import turbogears into the script it doesn't work anymore :-(
here the test script (it works only without turbogears):
import cherrypy
#import turbogears ##### uncomment this line and it doesn't work!!!!
def handle_error():
cherrypy.response.body = ["Sorry, an error 500 occured. The admin
has been notified."]
class Root:
_cp_config = {
"request.error_response": handle_error
}
@cherrypy.expose()
def index(self, **kw):
raise SyntaxError("forcing an error 500")
if __name__ == "__main__":
cherrypy.config.update(config='dev.cfg')
cherrypy.quickstart(Root(), "/", {})
jo wrote:
Thanks for replying to my question Christoph,
I did exactly as you said but it doesn't work yet....
Using pdb I can see that request.error_response has handle_errror()
assigned to,
before the error 500, but then it changes again, and I don't know
where and what changes it,
take a look ...
....debugging my controller...
import pdb;pdb.set_trace()
(Pdb) cherrypy.request.error_response.func_name
'handle_error'
### as you see at this point request.error_response has
indeed the handle_error assigned to
(Pdb) c
|*raise* SyntaxError*(*'test error 500'*)*|
-------and now lets see the value of request.error_response in the
traceback ...
URL: http://mysite/specie/
Module paste.evalexception.middleware:*306* in |respond|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>app_iter *=*
self*.*application*(*environ*,* detect_start_response*)*|
Module cherrypy._cpwsgi:*380* in |tail|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*return*
self*.*response_class*(*environ*,* start_response*,* self*.*cpapp*)*|
Module cherrypy._cpwsgi:*222* in |__init__|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>self*.*run*(**)*|
Module cherrypy._cpwsgi:*320* in |run|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>request*.*run*(*meth*,* path*,*
qs*,* rproto*,* headers*,* rfile*)*|
Module cherrypy._cprequest:*575* in |run|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>self*.*respond*(*pi*)*|
Module cherrypy._cprequest:*656* in |respond|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>response*.*body *=*
self*.*handler*(**)*|
Module cherrypy._cpdispatch:*34* in |__call__|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*return*
self*.*callable*(****self*.*args*,* ****self*.*kwargs*)*|
Module ?:*3* in |index| <http://josedev:8001/specie/#>
Module turbogears.identity.conditions:*235* in |require|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*return* fn*(*self*,* ***args*,*
****kwargs*)*|
Module ?:*3* in |index| <http://josedev:8001/specie/#>
Module turbogears.controllers:*360* in |expose|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>***args*,* ****kw*)*|
Module turbogears.database:*422* in |run_with_transaction|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*@**abstract**(**)*|
Module turbogears.database:*?* in |run_with_transaction|
<http://josedev:8001/specie/#>
Module turbogears.database:*495* in |sa_rwt|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>retval *=* func*(****args*,* ****kw*)*|
Module turbogears.controllers:*244* in |_expose|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*@**abstract**(**)*|
Module turbogears.controllers:*?* in |_expose|
<http://josedev:8001/specie/#>
Module turbogears.controllers:*389* in |<lambda>|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>fragment*,* options*,* args*,*
kw*)**)**)*|
Module turbogears.controllers:*425* in |_execute_func|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>output *=*
errorhandling*.*try_call*(*func*,* ***args*,* ****kw*)*|
Module turbogears.errorhandling:*82* in |try_call|
<http://josedev:8001/specie/#>
|>> <http://josedev:8001/specie/#>*return* func*(*self*,* ***args*,*
****kw*)*|
Module sicer.BASE.controller.tabelleCodifica.specie:*79* in |index|
<http://josedev:8001/specie/#>
|>>>| ||cherrypy*.*request*.*error_response||
|<bound method HTTPError.set_response of HTTPError(500, None)>
|
|>>>| ||cherrypy*.*request*.*error_response*.*func_name||
|'set_response'|
*cherrypy* |<module 'cherrypy' from
'../buildout/eggs/CherryPy-3.2.4-py2.6.egg/cherrypy/__init...
<http://josedev:8001/specie/#>|
*data* |{}
|
*pdb* |<module 'pdb' from
'../buildout/parts/python2.6/lib/python2.6/pdb.pyc'>|
*self* |<..controller.specie.Controller object at 0xc1d8a90>|
|>> <http://josedev:8001/specie/#>*raise* SyntaxError*(*'test error
500'*)*|
*SyntaxError: test error 500*
Il giorno venerdì 22 agosto 2014 22:26:11 UTC+2, Christoph Zwerschke
ha scritto:
Am 22.08.2014 um 10:54 schrieb Jose Soares:
> After having carefully read the documentation at
> http://www.turbogears.org/1.5/docs/ErrorReporting.html
<http://www.turbogears.org/1.5/docs/ErrorReporting.html>
> I decided to use "Method 3: Application-wide Catch-all with
error_response"
> Then, I wrote the following code in my controller:
Hi Jose,
your code is different from what is written in the docs.
Particularly,
the handle_error() should be taken literally from there.
Just copy the code in the docs into a module errorhandling.py,
then add
from .errorhandling import error_page, handle_error
at the top of your project, and add this to your RootController
class:
if config.get('error_catcher.on', False):
_cp_config = {
'error_page.default': error_page,
'request.error_response': handle_error
}
That definitely works for me, inculding the 500 errors.
-- Christoph
--
You received this message because you are subscribed to the Google
Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.
--
Jose Soares Da Silva _/_/
Sferacarta Net
Via Bazzanese 69 _/_/ _/_/_/
40033 Casalecchio di Reno _/_/ _/_/ _/_/
Bologna - Italy _/_/ _/_/ _/_/
Ph +39051591054 _/_/ _/_/ _/_/ _/_/
fax +390516131537 _/_/ _/_/ _/_/ _/_/
web:www.sferacarta.com _/_/_/ _/_/_/
Le informazioni contenute nella presente mail ed in ogni eventuale file
allegato sono riservate e, comunque, destinate esclusivamente alla persona o
ente sopraindicati, ai sensi del decreto legislativo 30 giugno 2003, n. 196. La
diffusione, distribuzione e/o copiatura della mail trasmessa, da parte di
qualsiasi soggetto diverso dal destinatario, sono vietate. La correttezza,
l’integrità e la sicurezza della presente mail non possono essere garantite. Se
avete ricevuto questa mail per errore, Vi preghiamo di contattarci
immediatamente e di eliminarla. Grazie.
This communication is intended only for use by the addressee, pursuant to
legislative decree 30 June 2003, n. 196. It may contain confidential or
privileged information. You should not copy or use it to disclose its contents
to any other person. Transmission cannot be guaranteed to be error-free,
complete and secure. If you are not the intended recipient and receive this
communication unintentionally, please inform us immediately and then delete
this message from your system. Thank you.
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.