All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.com.graphql_java_generator.exception.GraphQLRequestExecutionException Maven / Gradle / Ivy

The newest version!
/**
 * 
 */
package com.graphql_java_generator.exception;

import java.util.List;

import org.springframework.graphql.ResponseError;
import org.springframework.graphql.client.ClientGraphQlResponse;

import graphql.GraphQLError;

/**
 * Thrown when an error occurs during the request execution. This is typically when :
 * 
    *
  • One or more Bind Variable are missing
  • *
  • When an error occurred on server side. In this case (and only in this case), the {@link #getErrors()} method * returns non null value. This value is the server errors list.
  • *
* * @author etienne-sf */ public class GraphQLRequestExecutionException extends Exception implements GraphQLRequestExecutionExceptionInterface { private static final long serialVersionUID = 1L; private final List errors; private final Object data; private final ClientGraphQlResponse response; public GraphQLRequestExecutionException(String msg) { super(msg); this.errors = null; this.data = null; this.response = null; } public GraphQLRequestExecutionException(String msg, Throwable cause) { super(msg, cause); this.errors = null; this.data = null; this.response = null; } /** * Generates a new instance, from a non empty and non null list of {@link GraphQLError} * * @param errors * A list of GraphQL error messages * @param data * the data returned by the server, parsed by the plugin into the generated POJO that match the GraphQL * schema. For instance, when executing a full query that requests to query's field, it can for instance * contain the valid response data for one, while there is an error for the second queried field. */ public GraphQLRequestExecutionException(List errors, Object data, ClientGraphQlResponse response) { super(buildMessage(errors)); this.errors = errors; this.data = data; this.response = response; } @Override public List getErrors() { return this.errors; } @Override public Object getData() { return this.data; } @Override public ClientGraphQlResponse getResponse() { return this.response; } /** * * @param errors * A non null and non empty list of errors, a specified in the * GraphQL specification * @return */ private static String buildMessage(List errors) { StringBuilder sb = new StringBuilder(); boolean first = true; if (errors == null || errors.size() == 0) { sb.append("Unknown error"); //$NON-NLS-1$ } else { sb.append(errors.size()); sb.append(" error(s) occurred: "); //$NON-NLS-1$ for (ResponseError error : errors) { if (!first) sb.append(", "); //$NON-NLS-1$ sb.append(error.getMessage()); } } return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy