app: return HTTP errors in json format
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
14991ac3b9
commit
0ce53bd98f
|
@ -9,6 +9,7 @@ import mimetypes
|
|||
import logging
|
||||
import json
|
||||
import datetime
|
||||
import traceback
|
||||
import tornado
|
||||
import tornado.iostream
|
||||
import tornado.httputil
|
||||
|
@ -299,6 +300,13 @@ class AuthorizedRequestHandler(tornado.web.RequestHandler):
|
|||
conn = wsm.get_websocket(conn_id)
|
||||
return conn
|
||||
|
||||
def write_error(self, status_code, **kwargs):
|
||||
err = {'code': status_code, 'message': self._reason}
|
||||
if 'exc_info' in kwargs:
|
||||
err['traceback'] = "\n".join(
|
||||
traceback.format_exception(*kwargs['exc_info']))
|
||||
self.finish({'error': err})
|
||||
|
||||
# Due to the way Python treats multiple inheritance its best
|
||||
# to create a separate authorized handler for serving files
|
||||
class AuthorizedFileHandler(tornado.web.StaticFileHandler):
|
||||
|
@ -329,6 +337,13 @@ class AuthorizedFileHandler(tornado.web.StaticFileHandler):
|
|||
else:
|
||||
super(AuthorizedFileHandler, self).options()
|
||||
|
||||
def write_error(self, status_code, **kwargs):
|
||||
err = {'code': status_code, 'message': self._reason}
|
||||
if 'exc_info' in kwargs:
|
||||
err['traceback'] = "\n".join(
|
||||
traceback.format_exception(*kwargs['exc_info']))
|
||||
self.finish({'error': err})
|
||||
|
||||
class DynamicRequestHandler(AuthorizedRequestHandler):
|
||||
def initialize(self, callback, methods, need_object_parser=False,
|
||||
is_remote=True, wrap_result=True):
|
||||
|
@ -624,3 +639,10 @@ class AuthorizedErrorHandler(AuthorizedRequestHandler):
|
|||
|
||||
def check_xsrf_cookie(self):
|
||||
pass
|
||||
|
||||
def write_error(self, status_code, **kwargs):
|
||||
err = {'code': status_code, 'message': self._reason}
|
||||
if 'exc_info' in kwargs:
|
||||
err['traceback'] = "\n".join(
|
||||
traceback.format_exception(*kwargs['exc_info']))
|
||||
self.finish({'error': err})
|
||||
|
|
Loading…
Reference in New Issue