From cd01c7e21c0bfd8e2b53c91f9af491a1bf0e7d07 Mon Sep 17 00:00:00 2001 From: Cody Scott Date: Thu, 31 Jan 2019 12:03:44 -0500 Subject: [PATCH] Add HandledGraphQLError that does not log an exception --- graphql/error/__init__.py | 11 +++++++++-- graphql/error/base.py | 3 +++ graphql/execution/executor.py | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/graphql/error/__init__.py b/graphql/error/__init__.py index 7a627711..5d36fa2b 100644 --- a/graphql/error/__init__.py +++ b/graphql/error/__init__.py @@ -1,6 +1,13 @@ -from .base import GraphQLError +from .base import GraphQLError, HandledGraphQLError from .located_error import GraphQLLocatedError from .syntax_error import GraphQLSyntaxError from .format_error import format_error -__all__ = ["GraphQLError", "GraphQLLocatedError", "GraphQLSyntaxError", "format_error"] + +__all__ = [ + "GraphQLError", + "GraphQLLocatedError", + "GraphQLSyntaxError", + "HandledGraphQLError", + "format_error", +] diff --git a/graphql/error/base.py b/graphql/error/base.py index c57d0959..dcbb93d5 100644 --- a/graphql/error/base.py +++ b/graphql/error/base.py @@ -78,3 +78,6 @@ def locations(self): if self.positions and source: self._locations = [get_location(source, pos) for pos in self.positions] return self._locations + +class HandledGraphQLError(GraphQLError): + pass diff --git a/graphql/execution/executor.py b/graphql/execution/executor.py index 1b5e884e..e6cc0964 100644 --- a/graphql/execution/executor.py +++ b/graphql/execution/executor.py @@ -8,7 +8,7 @@ from six import string_types from promise import Promise, promise_for_dict, is_thenable -from ..error import GraphQLError, GraphQLLocatedError +from ..error import GraphQLError, GraphQLLocatedError, HandledGraphQLError from ..pyutils.default_ordered_dict import DefaultOrderedDict from ..pyutils.ordereddict import OrderedDict from ..utils.undefined import Undefined @@ -445,6 +445,8 @@ def resolve_or_error( # type: (...) -> Any try: return executor.execute(resolve_fn, source, info, **args) + except HandledGraphQLError: + raise except Exception as e: logger.exception( "An error occurred while resolving field {}.{}".format(