Skip to content

Instantly share code, notes, and snippets.

@MichaelAquilina
Created January 28, 2019 15:55
Show Gist options
  • Save MichaelAquilina/1153bab2e010e1e2ca33feb7bac2dd2b to your computer and use it in GitHub Desktop.
Save MichaelAquilina/1153bab2e010e1e2ca33feb7bac2dd2b to your computer and use it in GitHub Desktop.
from graphene_django.views import GraphQLView
from graphql.error import GraphQLError, format_error as format_graphql_error
class CustomGraphQLView(GraphQLView):
"""
Custom view that disables inserting detailed errors
"""
@staticmethod
def format_error(error):
if hasattr(error, "original_error") and not isinstance(error.original_error, GraphQLError):
# We do not want to format detailed messages in the response as this
# could be abused by attackers
return {"message": "An unknown error occurred"}
else:
return format_graphql_error(error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment