Class GenericExceptionResolver

java.lang.Object
org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
com.espacogeek.geek.exception.resolver.GenericExceptionResolver
All Implemented Interfaces:
org.springframework.graphql.execution.DataFetcherExceptionResolver

@Component public class GenericExceptionResolver extends org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
Centralized GraphQL exception resolver that maps domain exceptions to standardized error codes injected into the GraphQL extensions block under the key errorCode.

Error code categories:

  • 1xxx – Authentication errors
    • 1001 – Invalid credentials
    • 1002 – Token expired/invalid
  • 2xxx – Business rule errors
    • 2001 – Email already registered
    • 2003 – Media already exists
    • 2004 – Input validation failed
    • 2005 – Media already in library
  • 3xxx – Resource errors
    • 3403 – Access denied (e.g. private library)
    • 3404 – Resource not found (e.g. user or media)
  • 5xxx – Internal errors
    • 5000 – Unexpected server error
    • 5001 – Database error

Business exceptions never expose a stack trace to the client – only the message and errorCode are returned. Any unmapped exception is logged as a server error and returned to the client as code 5000.

  • Field Summary

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

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected graphql.GraphQLError
    resolveToSingleError(Throwable exception, graphql.schema.DataFetchingEnvironment env)
     

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

    isThreadLocalContextAware, resolveException, resolveToMultipleErrors, setThreadLocalContextAware

    Methods inherited from class java.lang.Object

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

    • GenericExceptionResolver

      public GenericExceptionResolver()
  • Method Details

    • resolveToSingleError

      protected graphql.GraphQLError resolveToSingleError(@NonNull Throwable exception, @NonNull graphql.schema.DataFetchingEnvironment env)
      Overrides:
      resolveToSingleError in class org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter