From 6a00c7aa82332f9c4971a19a3cb0306b65c42a4d Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Sun, 19 Jan 2020 23:11:07 -0500 Subject: [PATCH] Better error logging --- src/server/errors.py | 10 ++++------ src/server/handles.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/server/errors.py b/src/server/errors.py index c0b8af2..273e4bd 100644 --- a/src/server/errors.py +++ b/src/server/errors.py @@ -29,16 +29,14 @@ def make_error(error, exc=None) -> dict: return body -async def report_error(app, exc, msg=''): +async def report_error(app, exc, body: dict): try: if 'slack_webhook' in app['config']: - if msg: - msg = f'"{msg}"' - body = { - "text": f"Got `{type(exc).__name__}`: ```\n{str(exc)}```\n{msg}" + message = { + "text": f"Got `{type(exc).__name__}`: `\n{str(exc)}`\n```{body}```" } async with aiohttp.ClientSession() as sesh: - async with sesh.post(app['config']['slack_webhook'], json=body) as resp: + async with sesh.post(app['config']['slack_webhook'], json=message) as resp: await resp.wait_for_close() except Exception: diff --git a/src/server/handles.py b/src/server/handles.py index 63503f3..6f629a0 100644 --- a/src/server/handles.py +++ b/src/server/handles.py @@ -88,7 +88,7 @@ async def process_json(app, body: dict) -> dict: response['error'] = make_error('INVALID_PARAMS', err) else: response['error'] = make_error('INTERNAL', err) - await app['webhooks'].spawn(report_error(app, err)) + await app['webhooks'].spawn(report_error(app, err, body)) finally: end = time.time() -- 2.45.2