Skip to content

Commit ddc3a15

Browse files
committed
FieldAccessException falls back on request errors
A field may be missing not only due to field errors but also due to a failed request, so the error message should show either, whichever is not empty. Closes gh-348
1 parent d9540fe commit ddc3a15

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-graphql/src/main/java/org/springframework/graphql/client/FieldAccessException.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ public class FieldAccessException extends GraphQlClientException {
4343
public FieldAccessException(
4444
ClientGraphQlRequest request, ClientGraphQlResponse response, ClientResponseField field) {
4545

46-
super(initDefaultMessage(field), null, request);
46+
super(initDefaultMessage(field, response), null, request);
4747
this.response = response;
4848
this.field = field;
4949
}
5050

51-
private static String initDefaultMessage(ClientResponseField field) {
52-
return "Invalid field '" + field.getPath() + "', errors: " + field.getErrors();
51+
private static String initDefaultMessage(ClientResponseField field, ClientGraphQlResponse response) {
52+
return "Invalid field '" + field.getPath() + "', errors: " +
53+
(!field.getErrors().isEmpty() ? field.getErrors() : response.getErrors());
5354
}
5455

5556

0 commit comments

Comments
 (0)