Created
January 28, 2019 15:55
-
-
Save MichaelAquilina/1153bab2e010e1e2ca33feb7bac2dd2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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