Search in sources :

Example 6 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailOnQueryError.

@Test
void shouldFailOnQueryError() {
    fixture.returns("{" + "\"data\":{\"greeting\":null}," + "\"errors\":[{" + /**/
    "\"message\":\"currently can't greet\"," + /**/
    "\"locations\":[{\"line\":1,\"column\":2}]," + /**/
    "\"path\": [\"greeting\"],\n" + /**/
    "\"extensions\":{" + /**/
    "\"description\":\"some description\"," + /**/
    "\"queryPath\":[\"greeting\"]," + /**/
    "\"classification\":\"DataFetchingException\"," + /**/
    "\"code\":\"no-greeting\"}" + "}]}}");
    StringApi api = fixture.build(StringApi.class);
    GraphQLClientException thrown = catchThrowableOfType(api::greeting, GraphQLClientException.class);
    then(thrown).hasExactlyOneErrorWhich().hasMessage("currently can't greet").hasSourceLocation(1, 2).hasPath("greeting").hasErrorCode("no-greeting");
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 7 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException 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 8 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException 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 9 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ResultBuilder method readErrors.

private void readErrors() {
    if (!response.containsKey("errors") || response.isNull("errors"))
        return;
    JsonArray jsonErrors = response.getJsonArray("errors");
    if (jsonErrors == null)
        return;
    JsonArray unapplied = jsonErrors.stream().filter(error -> !apply(error)).collect(toJsonArray());
    if (unapplied.isEmpty())
        return;
    throw new GraphQLClientException("errors from service", unapplied.stream().map(ResponseReader::readError).collect(Collectors.toList()));
}
Also used : JsonCollectors.toJsonArray(javax.json.stream.JsonCollectors.toJsonArray) JsonArray(javax.json.JsonArray) JsonCollectors.toJsonArray(javax.json.stream.JsonCollectors.toJsonArray) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonReader(io.smallrye.graphql.client.impl.typesafe.json.JsonReader) JsonPatch(javax.json.JsonPatch) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) JsonArray(javax.json.JsonArray) ErrorOr(io.smallrye.graphql.client.typesafe.api.ErrorOr) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) JsonValue(javax.json.JsonValue) ResponseReader(io.smallrye.graphql.client.impl.ResponseReader) List(java.util.List) StringReader(java.io.StringReader) JsonUtils.isListOf(io.smallrye.graphql.client.impl.typesafe.json.JsonUtils.isListOf) JsonUtils(io.smallrye.graphql.client.impl.typesafe.json.JsonUtils) JsonException(javax.json.JsonException) Json(javax.json.Json) MethodInvocation(io.smallrye.graphql.client.impl.typesafe.reflection.MethodInvocation) JsonPointer(javax.json.JsonPointer) InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) ResponseReader(io.smallrye.graphql.client.impl.ResponseReader)

Example 10 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailToMapDirectNestedError.

@Test
void shouldFailToMapDirectNestedError() {
    fixture.returns(deeplyNestedError("null"));
    DeepErrorApi api = fixture.build(DeepErrorApi.class);
    GraphQLClientException throwable = catchThrowableOfType(api::outer, GraphQLClientException.class);
    thenDeeplyNestedErrorException(throwable);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Aggregations

GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)18 Test (org.junit.jupiter.api.Test)14 GraphQLError (io.smallrye.graphql.client.GraphQLError)2 InvalidResponseException (io.smallrye.graphql.client.InvalidResponseException)1 Response (io.smallrye.graphql.client.Response)1 ResponseImpl (io.smallrye.graphql.client.impl.ResponseImpl)1 ResponseReader (io.smallrye.graphql.client.impl.ResponseReader)1 JsonReader (io.smallrye.graphql.client.impl.typesafe.json.JsonReader)1 JsonUtils (io.smallrye.graphql.client.impl.typesafe.json.JsonUtils)1 JsonUtils.isListOf (io.smallrye.graphql.client.impl.typesafe.json.JsonUtils.isListOf)1 MethodInvocation (io.smallrye.graphql.client.impl.typesafe.reflection.MethodInvocation)1 ErrorOr (io.smallrye.graphql.client.typesafe.api.ErrorOr)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Collectors.joining (java.util.stream.Collectors.joining)1 Json (javax.json.Json)1 JsonArray (javax.json.JsonArray)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonException (javax.json.JsonException)1