From c3ace4be2ed231360dea42016ab1c959897371be Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 6 Oct 2018 09:22:11 +0100 Subject: [PATCH] Return 500 when an exception is thrown, never try to .encode None --- modules/rest_api.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/rest_api.py b/modules/rest_api.py index 3b6d515a..d60a874b 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -27,12 +27,16 @@ class Handler(http.server.BaseHTTPRequestHandler): code = 401 else: if path.startswith("/api/"): - response = _events.on("api").on(method).on(endpoint - ).call_for_result(params=params, path=args, data=data) + try: + event_response = _events.on("api").on(method).on( + endpoint).call_unsafe_for_result( + params=params, path=args, data=data) + except: + code = 500 - if response: - response = json.dumps(response, sort_keys=True, - indent=4) + if event_response: + response = json.dumps(event_response, + sort_keys=True, indent=4) code = 200 self.send_response(code)