mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] add console.format_exception and use it
This commit is contained in:
parent
f802d8139c
commit
68366fa685
2 changed files with 13 additions and 4 deletions
|
@ -50,6 +50,17 @@ console = Console()
|
|||
# pretty traceback using rich
|
||||
traceback.install(show_locals=True, extra_lines=6)
|
||||
|
||||
|
||||
# nice helper function for common usecase
|
||||
def _format_exception():
|
||||
with console.capture() as capture:
|
||||
console.print_exception()
|
||||
|
||||
return capture.get()
|
||||
|
||||
|
||||
console.format_exception = _format_exception
|
||||
|
||||
# Package functions
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from geventwebsocket import WebSocketError
|
|||
from bottle import request, response, Bottle, HTTPResponse
|
||||
from bottle import abort
|
||||
|
||||
from moulinette import msignals, m18n, env
|
||||
from moulinette import msignals, m18n, env, console
|
||||
from moulinette.actionsmap import ActionsMap
|
||||
from moulinette.core import MoulinetteError, MoulinetteValidationError
|
||||
from moulinette.interfaces import (
|
||||
|
@ -487,10 +487,8 @@ class _ActionsMapPlugin(object):
|
|||
except Exception as e:
|
||||
if isinstance(e, HTTPResponse):
|
||||
raise e
|
||||
import traceback
|
||||
|
||||
tb = traceback.format_exc()
|
||||
logs = {"route": _route, "arguments": arguments, "traceback": tb}
|
||||
logs = {"route": _route, "arguments": arguments, "traceback": console.format_traceback()}
|
||||
return HTTPResponse(json_encode(logs), 500)
|
||||
else:
|
||||
return format_for_response(ret)
|
||||
|
|
Loading…
Add table
Reference in a new issue