Last active
September 14, 2018 06:38
-
-
Save shahinism/28b68c702359577a9d6ff17552f35ded to your computer and use it in GitHub Desktop.
Capture exceptions on sentry when using Flask-GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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