Class GraphQLExceptionHandler

java.lang.Object
org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
it.univr.passportease.exception.GraphQLExceptionHandler
All Implemented Interfaces:
org.springframework.graphql.execution.DataFetcherExceptionResolver

@Component public class GraphQLExceptionHandler extends org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
This class handles the exceptions thrown by the GraphQL queries and mutations. It handles the following exceptions classes:
  • Forbidden Exceptions
  • Bad Request Exceptions
  • Not Found Exceptions
  • Unauthorized Exceptions
  • Field Summary

    Fields inherited from class org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static graphql.GraphQLError
    badRequestError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment)
    Handles the exceptions thrown by the GraphQL queries and mutations of type Bad Request.
    private static graphql.GraphQLError
    forbiddenError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment)
    Handles the exceptions thrown by the GraphQL queries and mutations of type Forbidden.
    private boolean
    isBadRequest(@NotNull Throwable exception)
    Checks if the exception is part of the Bad Request exceptions.
    private boolean
    isForbidden(@NotNull Throwable exception)
    Checks if the exception is part of the Forbidden exceptions.
    private boolean
    isNotFound(@NotNull Throwable exception)
    Checks if the exception is part of the Forbidden exceptions.
    private boolean
    isUnauthorized(@NotNull Throwable exception)
    Checks if the exception is part of the Unauthorized exceptions.
    private static graphql.GraphQLError
    notFoundError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment)
    Handles the exceptions thrown by the GraphQL queries and mutations of type Forbidden.
    protected graphql.GraphQLError
    resolveToSingleError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment)
    Resolves the exception to a single GraphQLError object containing the right error type, the message, the path and the location of the error.
    private static graphql.GraphQLError
    unauthorizedError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment)
    Handles the exceptions thrown by the GraphQL queries and mutations of type Unauthorized.

    Methods inherited from class org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter

    from, isThreadLocalContextAware, resolveException, resolveToMultipleErrors, setThreadLocalContextAware

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GraphQLExceptionHandler

      public GraphQLExceptionHandler()
  • Method Details

    • notFoundError

      private static graphql.GraphQLError notFoundError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment)
      Handles the exceptions thrown by the GraphQL queries and mutations of type Forbidden.
      Parameters:
      exception - The exception thrown by the query or mutation.
      environment - The environment of the query or mutation.
      Returns:
      a GraphQLError object containing the error type of Not Found, the message, the path and the location of the error.
    • unauthorizedError

      private static graphql.GraphQLError unauthorizedError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment)
      Handles the exceptions thrown by the GraphQL queries and mutations of type Unauthorized.
      Parameters:
      exception - The exception thrown by the query or mutation.
      environment - The environment of the query or mutation.
      Returns:
      a GraphQLError object containing the error type of Unauthorized, the message, the path and the location of the error.
    • badRequestError

      private static graphql.GraphQLError badRequestError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment)
      Handles the exceptions thrown by the GraphQL queries and mutations of type Bad Request.
      Parameters:
      exception - The exception thrown by the query or mutation.
      environment - The environment of the query or mutation.
      Returns:
      a GraphQLError object containing the error type of Bad Request,
    • forbiddenError

      private static graphql.GraphQLError forbiddenError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment)
      Handles the exceptions thrown by the GraphQL queries and mutations of type Forbidden.
      Parameters:
      exception - The exception thrown by the query or mutation.
      environment - The environment of the query or mutation.
      Returns:
      a GraphQLError object containing the error type of Forbidden,
    • isNotFound

      private boolean isNotFound(@NotNull @NotNull Throwable exception)
      Checks if the exception is part of the Forbidden exceptions.
      Parameters:
      exception - The exception thrown by the query or mutation.
      Returns:
      true if the exception is part of the Forbidden exceptions, false otherwise.
    • isBadRequest

      private boolean isBadRequest(@NotNull @NotNull Throwable exception)
      Checks if the exception is part of the Bad Request exceptions.
      Parameters:
      exception - The exception thrown by the query or mutation.
      Returns:
      true if the exception is part of the Unauthorized exceptions, false otherwise.
    • isUnauthorized

      private boolean isUnauthorized(@NotNull @NotNull Throwable exception)
      Checks if the exception is part of the Unauthorized exceptions.
      Parameters:
      exception - The exception thrown by the query or mutation.
      Returns:
      true if the exception is part of the Unauthorized exceptions, false otherwise.
    • isForbidden

      private boolean isForbidden(@NotNull @NotNull Throwable exception)
      Checks if the exception is part of the Forbidden exceptions.
      Parameters:
      exception - The exception thrown by the query or mutation.
      Returns:
      true if the exception is part of the Forbidden exceptions, false otherwise.
    • resolveToSingleError

      protected graphql.GraphQLError resolveToSingleError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment)
      Resolves the exception to a single GraphQLError object containing the right error type, the message, the path and the location of the error.
      Overrides:
      resolveToSingleError in class org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
      Parameters:
      exception - the exception to resolve to a single GraphQLError
      environment - the environment for the invoked DataFetcher
      Returns:
      a GraphQLError object containing the right error type, the message, the path and the location of the error. If the exception is not part of the handled exceptions, it returns the default error. (Internal Server Error)