use of io.smallrye.graphql.client.GraphQLError in project smallrye-graphql by smallrye.
the class GraphQLTransportWSSubprotocolHandler method handleOperationError.
private void handleOperationError(String operationId, JsonArray errors) {
List<GraphQLError> parsedErrors = errors.stream().map(ResponseReader::readError).collect(Collectors.toList());
GraphQLClientException exception = new GraphQLClientException("Received an error", parsedErrors);
UniEmitter<? super String> emitter = uniOperations.remove(operationId);
if (emitter != null) {
emitter.fail(exception);
} else {
MultiEmitter<? super String> multiEmitter = multiOperations.remove(operationId);
if (multiEmitter != null) {
multiEmitter.fail(exception);
}
}
}
use of io.smallrye.graphql.client.GraphQLError in project smallrye-graphql by smallrye.
the class GraphQLWSSubprotocolHandler method handleOperationError.
private void handleOperationError(String operationId, JsonObject error) {
GraphQLError parsedError = ResponseReader.readError(error);
GraphQLClientException exception = new GraphQLClientException("Received an error", parsedError);
UniEmitter<? super String> emitter = uniOperations.remove(operationId);
if (emitter != null) {
emitter.fail(exception);
} else {
MultiEmitter<? super String> multiEmitter = multiOperations.remove(operationId);
if (multiEmitter != null) {
multiEmitter.fail(exception);
}
}
}
use of io.smallrye.graphql.client.GraphQLError in project smallrye-graphql by smallrye.
the class ResponseReader method readFrom.
public static ResponseImpl readFrom(String input, Map<String, List<String>> headers) {
if (input == null) {
throw SmallRyeGraphQLClientMessages.msg.nullResponseBody();
}
JsonReader jsonReader = Json.createReader(new StringReader(input));
JsonObject jsonResponse;
try {
jsonResponse = jsonReader.readObject();
} catch (Exception e) {
throw SmallRyeGraphQLClientMessages.msg.cannotParseResponse(input, e);
}
JsonObject data = null;
if (jsonResponse.containsKey("data")) {
if (!jsonResponse.isNull("data")) {
data = jsonResponse.getJsonObject("data");
} else {
SmallRyeGraphQLClientLogging.log.noDataInResponse();
}
}
List<GraphQLError> errors = null;
if (jsonResponse.containsKey("errors")) {
errors = new ArrayList<>();
for (JsonValue error : jsonResponse.getJsonArray("errors")) {
errors.add(readError(error));
}
}
return new ResponseImpl(data, errors, headers);
}
Aggregations