Skip to content

Instantly share code, notes, and snippets.

@shahinism
Last active September 14, 2018 06:38
Show Gist options
  • Save shahinism/28b68c702359577a9d6ff17552f35ded to your computer and use it in GitHub Desktop.
Save shahinism/28b68c702359577a9d6ff17552f35ded to your computer and use it in GitHub Desktop.
Capture exceptions on sentry when using Flask-GraphQL
# By default Flask-GraphQL will handle all exceptions
# by showing a proper error message on the api.
from factory import sentry
from utils.logger import logger
class SentryMiddleware(object):
@classmethod
def on_error(cls, error):
logger.error(error)
try:
raise error
except Exception as e:
# only capture it if sentry is configured in app context
# helps in development environment
if sentry.client:
sentry.captureException()
return error
@classmethod
def resolve(cls, next, root, info, *args, **kwargs):
return next(root, info, *args, **kwargs).catch(cls.on_error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment