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
This commit is contained in:
rstoyanchev
2022-04-28 20:52:07 +01:00
parent d9540fe3c3
commit ddc3a1503c

View File

@@ -43,13 +43,14 @@ public class FieldAccessException extends GraphQlClientException {
public FieldAccessException( public FieldAccessException(
ClientGraphQlRequest request, ClientGraphQlResponse response, ClientResponseField field) { ClientGraphQlRequest request, ClientGraphQlResponse response, ClientResponseField field) {
super(initDefaultMessage(field), null, request); super(initDefaultMessage(field, response), null, request);
this.response = response; this.response = response;
this.field = field; this.field = field;
} }
private static String initDefaultMessage(ClientResponseField field) { private static String initDefaultMessage(ClientResponseField field, ClientGraphQlResponse response) {
return "Invalid field '" + field.getPath() + "', errors: " + field.getErrors(); return "Invalid field '" + field.getPath() + "', errors: " +
(!field.getErrors().isEmpty() ? field.getErrors() : response.getErrors());
} }