Skip to content

Conversation

Siecje
Copy link

@Siecje Siecje commented Jan 31, 2019

I'm trying to send a custom error message in a web response. I can raise an exception to do that but I'm also getting sentry reports that I don't want.

In a Django project Sentry is setup to handle logging. When graphql-core logs this exception I get a sentry report.

https://github.com/graphql-python/graphql-core/blob/9202021fc87db9c175e115016cd53e5d9d085ac6/graphql/execution/executor.py#L446-L455

I want to be able to prevent the sentry report.

To send a custom error message back to the user you would just raise HandledGraphQLError(msg).

Here is the Django logging config for reference. Let me know if there is a better solution.

 LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'root': { 'level': 'WARNING', 'handlers': ['sentry'], }, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s ' '%(process)d %(thread)d %(message)s' }, }, 'handlers': { 'sentry': { # To capture more than ERROR, change to WARNING, INFO, etc. 'level': 'ERROR', 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', 'tags': { 'build_number': os.environ.get('BUILD_NUMBER', 'none'), 'env': RUNNING_ENV } }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose' } }, 'loggers': { 'raven': { 'level': 'DEBUG', 'handlers': ['console'], 'propagate': False, }, 'sentry.errors': { 'level': 'DEBUG', 'handlers': ['console'], 'propagate': False, } }, } 
@ziXet
Copy link

ziXet commented Feb 4, 2019

There is another way! adding a filter to the django LOGGING setting and changing the level of the log record based on the raised exception.

LOGGING = { 'filters': { 'graphql_log_filter': { '()': GraphQLLogFIlter } }, 'graphql.execution.executor': { 'level': 'INFO', 'handlers': ['console'], 'filters': ['graphql_log_filter'] } } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants