python - How to customize error response in a Turbogears2 controller -


i'm using turbogears2 develop small web application. , in of "controllers", response client json object error information inside instead of html page follows standard error page template, because ajax client can read error message , have it's own way display it.

there multiple ways can achieve this. if bound controller can register controller wrapper them (using tg.hooks.wrap_controller) , return json instead of plain error when needed. controller wrappers documented on http://turbogears.readthedocs.org/en/latest/turbogears/hooks.html#controller-wrappers

otherwise options use decorator on controller function catch error. done tgext.crudwhen reporting json errors through catch_errors custom decorator: https://github.com/turbogears/tgext.crud/blob/master/tgext/crud/decorators.py#l114

the controller wrapper solution more powerful can applied third party controllers. otherwise can hijack errorcontroller in controllers/error.py return json using json.dumps (turbogears returns response when it's string or tg.response instance).


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -