1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Better sentry error reporting

This commit is contained in:
Steffo 2019-01-02 19:37:05 +01:00
parent 8e1f281cbf
commit 2bcb842114
2 changed files with 21 additions and 1 deletions

View file

@ -14,4 +14,5 @@ markovify
praw praw
dice dice
raven[flask] raven[flask]
coloredlogs coloredlogs
sentry_sdk

View file

@ -8,7 +8,9 @@ import typing
import telegram import telegram
import sys import sys
import coloredlogs import coloredlogs
import requests
from dirty import Dirty from dirty import Dirty
from sentry_sdk import configure_scope
logging.getLogger().disabled = True logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -34,6 +36,23 @@ def update_block(session: db.Session, block: list, delay: float=0, change_callba
t = time.clock() t = time.clock()
try: try:
change = item.update(session=session) change = item.update(session=session)
except requests.exceptions.HTTPError as e:
with configure_scope() as scope:
if str(e.response.status_code).startswith("5"):
scope.level = "warning"
logger.warning(f"Server error {sys.exc_info()} while updating {repr(item)}.")
else:
scope.level = "error"
logger.error(f"Error {sys.exc_info()} while updating {repr(item)}.")
sentry.extra_context({
"item": repr(item),
"response": {
"code": e.response.status_code,
"text": e.response.text
}
})
sentry.captureException()
continue
except Exception as e: except Exception as e:
logger.warning(f"Error {sys.exc_info()} while updating {repr(item)}.") logger.warning(f"Error {sys.exc_info()} while updating {repr(item)}.")
sentry.extra_context({ sentry.extra_context({