Package it.univr.passportease.exception
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
-
Method Summary
Modifier and TypeMethodDescriptionprivate static graphql.GraphQLError
badRequestError
(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Handles the exceptions thrown by the GraphQL queries and mutations of typeBad 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 typeForbidden
.private boolean
isBadRequest
(@NotNull Throwable exception) Checks if the exception is part of theBad Request
exceptions.private boolean
isForbidden
(@NotNull Throwable exception) Checks if the exception is part of theForbidden
exceptions.private boolean
isNotFound
(@NotNull Throwable exception) Checks if the exception is part of theForbidden
exceptions.private boolean
isUnauthorized
(@NotNull Throwable exception) Checks if the exception is part of theUnauthorized
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 typeForbidden
.protected graphql.GraphQLError
resolveToSingleError
(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Resolves the exception to a singleGraphQLError
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 typeUnauthorized
.Methods inherited from class org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
from, isThreadLocalContextAware, resolveException, resolveToMultipleErrors, setThreadLocalContextAware
-
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 typeForbidden
.- 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 ofNot 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 typeUnauthorized
.- 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 ofUnauthorized
, 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 typeBad 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 ofBad 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 typeForbidden
.- 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 ofForbidden
,
-
isNotFound
Checks if the exception is part of theForbidden
exceptions.- Parameters:
exception
- The exception thrown by the query or mutation.- Returns:
true
if the exception is part of theForbidden
exceptions,false
otherwise.
-
isBadRequest
Checks if the exception is part of theBad Request
exceptions.- Parameters:
exception
- The exception thrown by the query or mutation.- Returns:
true
if the exception is part of theUnauthorized
exceptions,false
otherwise.
-
isUnauthorized
Checks if the exception is part of theUnauthorized
exceptions.- Parameters:
exception
- The exception thrown by the query or mutation.- Returns:
true
if the exception is part of theUnauthorized
exceptions,false
otherwise.
-
isForbidden
Checks if the exception is part of theForbidden
exceptions.- Parameters:
exception
- The exception thrown by the query or mutation.- Returns:
true
if the exception is part of theForbidden
exceptions,false
otherwise.
-
resolveToSingleError
protected graphql.GraphQLError resolveToSingleError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment) Resolves the exception to a singleGraphQLError
object containing the right error type, the message, the path and the location of the error.- Overrides:
resolveToSingleError
in classorg.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
- Parameters:
exception
- the exception to resolve to a singleGraphQLError
environment
- the environment for the invokedDataFetcher
- 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)
-