Log errors caught when trying to execute API endpoints

This commit is contained in:
jesopo 2018-11-06 17:22:50 +00:00
parent 2bdac13752
commit 08355c026e

View file

@ -7,6 +7,7 @@ from src import ModuleManager, utils
_bot = None
_events = None
_log = None
class Handler(http.server.BaseHTTPRequestHandler):
timeout = 10
def _handle(self, method, path, data="", params={}):
@ -32,7 +33,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
event_response = _events.on("api").on(method).on(
endpoint).call_unsafe_for_result(params=params,
path=args, data=data, headers=dict(self.headers))
except:
except Exception as e:
_log.error("failed to call API endpoint \"%s\"",
[path], exc_info=True)
code = 500
if not event_response == None:
@ -80,6 +83,9 @@ class Module(ModuleManager.BaseModule):
global _events
_events = self.events
global _log
_log = self.log
if self.bot.get_setting("rest-api", False):
self.httpd = http.server.HTTPServer(("", 5000), Handler)
self.httpd.socket = ssl.wrap_socket(self.httpd.socket,