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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static graphql.GraphQLErrorbadRequestError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Handles the exceptions thrown by the GraphQL queries and mutations of typeBad Request.private static graphql.GraphQLErrorforbiddenError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Handles the exceptions thrown by the GraphQL queries and mutations of typeForbidden.private booleanisBadRequest(@NotNull Throwable exception) Checks if the exception is part of theBad Requestexceptions.private booleanisForbidden(@NotNull Throwable exception) Checks if the exception is part of theForbiddenexceptions.private booleanisNotFound(@NotNull Throwable exception) Checks if the exception is part of theForbiddenexceptions.private booleanisUnauthorized(@NotNull Throwable exception) Checks if the exception is part of theUnauthorizedexceptions.private static graphql.GraphQLErrornotFoundError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Handles the exceptions thrown by the GraphQL queries and mutations of typeForbidden.protected graphql.GraphQLErrorresolveToSingleError(@NotNull Throwable exception, @NotNull graphql.schema.DataFetchingEnvironment environment) Resolves the exception to a singleGraphQLErrorobject containing the right error type, the message, the path and the location of the error.private static graphql.GraphQLErrorunauthorizedError(@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
GraphQLErrorobject 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
GraphQLErrorobject 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
GraphQLErrorobject 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
GraphQLErrorobject containing the error type ofForbidden,
-
isNotFound
Checks if the exception is part of theForbiddenexceptions.- Parameters:
exception- The exception thrown by the query or mutation.- Returns:
trueif the exception is part of theForbiddenexceptions,falseotherwise.
-
isBadRequest
Checks if the exception is part of theBad Requestexceptions.- Parameters:
exception- The exception thrown by the query or mutation.- Returns:
trueif the exception is part of theUnauthorizedexceptions,falseotherwise.
-
isUnauthorized
Checks if the exception is part of theUnauthorizedexceptions.- Parameters:
exception- The exception thrown by the query or mutation.- Returns:
trueif the exception is part of theUnauthorizedexceptions,falseotherwise.
-
isForbidden
Checks if the exception is part of theForbiddenexceptions.- Parameters:
exception- The exception thrown by the query or mutation.- Returns:
trueif the exception is part of theForbiddenexceptions,falseotherwise.
-
resolveToSingleError
protected graphql.GraphQLError resolveToSingleError(@NotNull @NotNull Throwable exception, @NotNull @NotNull graphql.schema.DataFetchingEnvironment environment) Resolves the exception to a singleGraphQLErrorobject containing the right error type, the message, the path and the location of the error.- Overrides:
resolveToSingleErrorin classorg.springframework.graphql.execution.DataFetcherExceptionResolverAdapter- Parameters:
exception- the exception to resolve to a singleGraphQLErrorenvironment- the environment for the invokedDataFetcher- Returns:
- a
GraphQLErrorobject 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)
-