2

I have made an application in Tornado that simple handles some REST api.

This is the code

class Application(tornado.web.Application):
def __init__(self):
    handlers = [
        ("/datasets/add", DatasetAdd),
        ("/projects/create", ProjectCreate),
        ("/scenarios/execute", ExecuteScenario)
    ]
    tornado.web.Application.__init__(self, handlers, debug=False)


def start():
    port = config['SERVER_PORT']
    num_processes = config['SERVER_NUM_PROCESSES']
    logging.info("Starting server on port {} using {} process ...".format(port, num_processes))
    app = Application()
    if sys.platform == 'win32':
        logging.warning('Running on Windows is not officially supported and is recommended only for            development use')

server = tornado.httpserver.HTTPServer(app)
server.bind(port, address='127.0.0.1')
if sys.platform == 'win32' and num_processes > 1:
    num_processes = 1  # fork process is not supported on Windows

server.start(num_processes)  # forks NUM process per cpu
logging.info("Server started.")
logging.info("Waiting for requests ...")
IOLoop.current().start()
logging.info('Server stopped.')

When I make a call to scenarios/execute, for example, it returns a

<html>
<title>500: Internal Server Error</title>

<body>500: Internal Server Error</body>

</html>

... but I want it to return the full stack trace for the error to the caller (it is Python code executed in same project...)

How can I do?

Lore
  • 1,286
  • 1
  • 22
  • 57
  • For tornado specifically you shoud overwrite the `RequestHandler.write_error()` method. **The following is from the [docs](https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write_error):** Override to implement custom error pages. write_error may call write, render, set_header, etc to produce output as usual. If this error was caused by an uncaught exception (including HTTPError), an exc_info triple will be available as `kwargs["exc_info"]`. So returning or adding `kwargs["exc_info"]` should do the trick. – klaas Aug 30 '20 at 20:39
  • 3
    **Question should be reopened**: As a remark, I think this question was closed to early since I cannot find any explanation on adding a traceback/Stacktrace to a tornado ap in the linked duplicate. And this was clearly the intention of the question. The linked "duplicate" only shows this how to do it in python in general. Which is related and helpful but not quite to the point. – klaas Aug 30 '20 at 20:47
  • @klaas pleas flag it – Lore Jul 01 '21 at 12:37
  • @klaas or write a post in meta – Lore Jul 01 '21 at 12:37

0 Answers0