include the traceback in the response when a server method fails

example:

$ curl  --unix-socket .subiquity/socket a/dry_run/crash
Traceback (most recent call last):
  File "/home/mwhudson/src/subiquity/subiquity/common/api/server.py", line 122, in handler
    result = await implementation(**args)
  File "/home/mwhudson/src/subiquity/subiquity/server/dryrun.py", line 24, in crash_GET
    1/0
ZeroDivisionError: division by zero
This commit is contained in:
Michael Hudson-Doyle 2021-05-13 05:31:34 +12:00
parent 541b483fb9
commit f339620a50
1 changed files with 3 additions and 0 deletions

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import inspect
import traceback
from aiohttp import web
@ -123,7 +124,9 @@ def _make_handler(controller, definition, implementation, serializer):
serializer.serialize(def_ret_ann, result),
headers={'x-status': 'ok'})
except Exception as exc:
tb = traceback.TracebackException.from_exception(exc)
resp = web.Response(
text="".join(tb.format()),
status=500,
headers={
'x-status': 'error',