Tornado Error Handling -


i want able handle nicer error that's displayed if type incorrect url e.g. localhost:8000/afdadsfdkfads

i ugly python traceback message because tornado.web.httperror exception thrown. know can use regex catch scenarios other proper urls figure there must way handle error within tornado.

i know can use write_error() when extending tornado.web.requesthandler because error happening in tornado.web.application class don't know how deal it. think might have class tornado.web.errorhandler(application, request, **kwargs) i'm unsure.

also can tell me if i'm in tornado.web.requesthandler method , perform raise keyerror or other exception without catching why write_error() isn't invoked? seems exception ignored.

to provide custom 404 page make handler calls self.set_status(404) (in addition producing whatever output want) , set default_handler_class in application constructor keyword arguments.

class my404handler(requesthandler):     # override prepare() instead of get() cover possible http methods.     def prepare(self):         self.set_status(404)         self.render("404.html")  app = application(..., default_handler_class=my404handler) 

you don't want use errorhandler: it's easy way return specified status code doesn't give control of output.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -