Search in sources :

Example 1 with GraphQLError

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);
        }
    }
}
Also used : GraphQLError(io.smallrye.graphql.client.GraphQLError) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException)

Example 2 with GraphQLError

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);
        }
    }
}
Also used : GraphQLError(io.smallrye.graphql.client.GraphQLError) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException)

Example 3 with GraphQLError

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);
}
Also used : StringReader(java.io.StringReader) JsonValue(javax.json.JsonValue) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) GraphQLError(io.smallrye.graphql.client.GraphQLError)

Aggregations

GraphQLError (io.smallrye.graphql.client.GraphQLError)3 GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)2 StringReader (java.io.StringReader)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1 JsonValue (javax.json.JsonValue)1