From 7a6acc83a51976766ff6c61b4a4820bf8e377a43 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 12 Nov 2021 11:54:13 +1000 Subject: [PATCH] when a post handler fails, log the traceback to the console https://forums.ankiweb.net/t/cant-change-note-type/14809 --- qt/aqt/mediasrv.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index 948c418c8..f67df5f44 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -485,11 +485,15 @@ def _extract_collection_post_request(path: str) -> DynamicRequest | NotFound: if handler := post_handlers.get(path): # convert bytes/None into response def wrapped() -> Response: - if data := handler(): - response = flask.make_response(data) - response.headers["Content-Type"] = "application/binary" - else: - response = flask.make_response("", HTTPStatus.NO_CONTENT) + try: + if data := handler(): + response = flask.make_response(data) + response.headers["Content-Type"] = "application/binary" + else: + response = flask.make_response("", HTTPStatus.NO_CONTENT) + except: + print(traceback.format_exc()) + response = flask.make_response("", HTTPStatus.INTERNAL_SERVER_ERROR) return response return wrapped