Log errors caught when trying to execute API endpoints
This commit is contained in:
parent
2bdac13752
commit
08355c026e
1 changed files with 7 additions and 1 deletions
|
@ -7,6 +7,7 @@ from src import ModuleManager, utils
|
||||||
|
|
||||||
_bot = None
|
_bot = None
|
||||||
_events = None
|
_events = None
|
||||||
|
_log = None
|
||||||
class Handler(http.server.BaseHTTPRequestHandler):
|
class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
timeout = 10
|
timeout = 10
|
||||||
def _handle(self, method, path, data="", params={}):
|
def _handle(self, method, path, data="", params={}):
|
||||||
|
@ -32,7 +33,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||||
event_response = _events.on("api").on(method).on(
|
event_response = _events.on("api").on(method).on(
|
||||||
endpoint).call_unsafe_for_result(params=params,
|
endpoint).call_unsafe_for_result(params=params,
|
||||||
path=args, data=data, headers=dict(self.headers))
|
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
|
code = 500
|
||||||
|
|
||||||
if not event_response == None:
|
if not event_response == None:
|
||||||
|
@ -80,6 +83,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
global _events
|
global _events
|
||||||
_events = self.events
|
_events = self.events
|
||||||
|
|
||||||
|
global _log
|
||||||
|
_log = self.log
|
||||||
|
|
||||||
if self.bot.get_setting("rest-api", False):
|
if self.bot.get_setting("rest-api", False):
|
||||||
self.httpd = http.server.HTTPServer(("", 5000), Handler)
|
self.httpd = http.server.HTTPServer(("", 5000), Handler)
|
||||||
self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
|
self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
|
||||||
|
|
Loading…
Reference in a new issue