Better error logging
This commit is contained in:
parent
25eb4f9acd
commit
6a00c7aa82
2 changed files with 5 additions and 7 deletions
|
@ -29,16 +29,14 @@ def make_error(error, exc=None) -> dict:
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
async def report_error(app, exc, msg=''):
|
async def report_error(app, exc, body: dict):
|
||||||
try:
|
try:
|
||||||
if 'slack_webhook' in app['config']:
|
if 'slack_webhook' in app['config']:
|
||||||
if msg:
|
message = {
|
||||||
msg = f'"{msg}"'
|
"text": f"Got `{type(exc).__name__}`: `\n{str(exc)}`\n```{body}```"
|
||||||
body = {
|
|
||||||
"text": f"Got `{type(exc).__name__}`: ```\n{str(exc)}```\n{msg}"
|
|
||||||
}
|
}
|
||||||
async with aiohttp.ClientSession() as sesh:
|
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()
|
await resp.wait_for_close()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -88,7 +88,7 @@ async def process_json(app, body: dict) -> dict:
|
||||||
response['error'] = make_error('INVALID_PARAMS', err)
|
response['error'] = make_error('INVALID_PARAMS', err)
|
||||||
else:
|
else:
|
||||||
response['error'] = make_error('INTERNAL', err)
|
response['error'] = make_error('INTERNAL', err)
|
||||||
await app['webhooks'].spawn(report_error(app, err))
|
await app['webhooks'].spawn(report_error(app, err, body))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
end = time.time()
|
end = time.time()
|
||||||
|
|
Loading…
Reference in a new issue