serializes error messages into json format

This commit is contained in:
Oleg Silkin 2020-04-09 16:55:07 -04:00
parent b4377b2f54
commit 3cce89cbac

View file

@ -1,3 +1,5 @@
import json
import logging import logging
import aiohttp import aiohttp
@ -32,8 +34,11 @@ def make_error(error, exc=None) -> dict:
async def report_error(app, exc, body: dict): async def report_error(app, exc, body: dict):
try: try:
if 'slack_webhook' in app['config']: if 'slack_webhook' in app['config']:
body_dump = json.dumps(body, indent=4)
exec_name = type(exc).__name__
exec_body = str(exc)
message = { message = {
"text": f"Got `{type(exc).__name__}`: `\n{str(exc)}`\n```{body}```" "text": f"Got `{exec_name}`: `\n{exec_body}`\n```{body_dump}```"
} }
async with aiohttp.ClientSession() as sesh: async with aiohttp.ClientSession() as sesh:
async with sesh.post(app['config']['slack_webhook'], json=message) as resp: async with sesh.post(app['config']['slack_webhook'], json=message) as resp: