Skip to content

Commit f020d08

Browse files
19: Fix DataFetcherExceptionHandler example
fixes: #19
1 parent f4b3d8d commit f020d08

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

content/documentation/v12/execution.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,20 @@ partial results with errors.
8080
Here is the code for the standard behaviour.
8181

8282
{{< highlight java "linenos=table" >}}
83-
8483
public class SimpleDataFetcherExceptionHandler implements DataFetcherExceptionHandler {
85-
private static final Logger log = LoggerFactory.getLogger(SimpleDataFetcherExceptionHandler.class);
84+
85+
private static final Logger logNotSafe = LogKit.getNotPrivacySafeLogger(SimpleDataFetcherExceptionHandler.class);
8686

8787
@Override
88-
public void accept(DataFetcherExceptionHandlerParameters handlerParameters) {
88+
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
8989
Throwable exception = handlerParameters.getException();
90-
SourceLocation sourceLocation = handlerParameters.getField().getSourceLocation();
90+
SourceLocation sourceLocation = handlerParameters.getSourceLocation();
9191
ExecutionPath path = handlerParameters.getPath();
9292

9393
ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, exception, sourceLocation);
94-
handlerParameters.getExecutionContext().addError(error);
95-
log.warn(error.getMessage(), exception);
94+
logNotSafe.warn(error.getMessage(), exception);
95+
96+
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
9697
}
9798
}
9899
{{< / highlight >}}

content/documentation/v13/execution.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,20 @@ partial results with errors.
8080
Here is the code for the standard behaviour.
8181

8282
{{< highlight java "linenos=table" >}}
83-
8483
public class SimpleDataFetcherExceptionHandler implements DataFetcherExceptionHandler {
85-
private static final Logger log = LoggerFactory.getLogger(SimpleDataFetcherExceptionHandler.class);
84+
85+
private static final Logger logNotSafe = LogKit.getNotPrivacySafeLogger(SimpleDataFetcherExceptionHandler.class);
8686

8787
@Override
88-
public void accept(DataFetcherExceptionHandlerParameters handlerParameters) {
88+
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
8989
Throwable exception = handlerParameters.getException();
90-
SourceLocation sourceLocation = handlerParameters.getField().getSourceLocation();
90+
SourceLocation sourceLocation = handlerParameters.getSourceLocation();
9191
ExecutionPath path = handlerParameters.getPath();
9292

9393
ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, exception, sourceLocation);
94-
handlerParameters.getExecutionContext().addError(error);
95-
log.warn(error.getMessage(), exception);
94+
logNotSafe.warn(error.getMessage(), exception);
95+
96+
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
9697
}
9798
}
9899
{{< / highlight >}}

content/documentation/v14/execution.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,20 @@ partial results with errors.
8080
Here is the code for the standard behaviour.
8181

8282
{{< highlight java "linenos=table" >}}
83-
8483
public class SimpleDataFetcherExceptionHandler implements DataFetcherExceptionHandler {
85-
private static final Logger log = LoggerFactory.getLogger(SimpleDataFetcherExceptionHandler.class);
84+
85+
private static final Logger logNotSafe = LogKit.getNotPrivacySafeLogger(SimpleDataFetcherExceptionHandler.class);
8686

8787
@Override
88-
public void accept(DataFetcherExceptionHandlerParameters handlerParameters) {
88+
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
8989
Throwable exception = handlerParameters.getException();
90-
SourceLocation sourceLocation = handlerParameters.getField().getSourceLocation();
90+
SourceLocation sourceLocation = handlerParameters.getSourceLocation();
9191
ExecutionPath path = handlerParameters.getPath();
9292

9393
ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, exception, sourceLocation);
94-
handlerParameters.getExecutionContext().addError(error);
95-
log.warn(error.getMessage(), exception);
94+
logNotSafe.warn(error.getMessage(), exception);
95+
96+
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
9697
}
9798
}
9899
{{< / highlight >}}

0 commit comments

Comments
 (0)