Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Update `extensions/mask_errors.py` to handle pre-execution errors and execution errors separately.
24 changes: 11 additions & 13 deletions strawberry/extensions/mask_errors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections.abc import Iterator
from typing import Any, Callable
from typing import Callable

from graphql.error import GraphQLError
from graphql.execution import ExecutionResult

from strawberry.extensions.base_extension import SchemaExtension

Expand Down Expand Up @@ -34,30 +33,29 @@ def anonymise_error(self, error: GraphQLError) -> GraphQLError:
original_error=None,
)

# TODO: proper typing
def _process_result(self, result: Any) -> None:
if not result.errors:
return

def _process_errors(self, errors: list[GraphQLError]) -> list[GraphQLError]:
processed_errors: list[GraphQLError] = []

for error in result.errors:
for error in errors:
if self.should_mask_error(error):
processed_errors.append(self.anonymise_error(error))
else:
processed_errors.append(error)

result.errors = processed_errors
return processed_errors

def on_operation(self) -> Iterator[None]:
yield

pre_execution_errors = self.execution_context.pre_execution_errors or []
self.execution_context.pre_execution_errors = self._process_errors(
pre_execution_errors
)

result = self.execution_context.result

if isinstance(result, ExecutionResult):
self._process_result(result)
elif result:
self._process_result(result.initial_result)
if result is not None and result.errors:
result.errors = self._process_errors(result.errors)


__all__ = ["MaskErrors"]
Loading