Is there a way in graphql-kotlin to handle excepti...
# graphql-kotlin
b
Is there a way in graphql-kotlin to handle exceptions and change their message and/or the response? I’ve got spring security setup with method level security working with
@Secured
and it throws an exception (
AuthenticationCredentialsNotFoundException
) when expected, but how do i define an “error resolver” that can take that exception and turn it into a more meaningful message (ie: right now it’s
An Authentication object was not found in the SecurityContext
for that exception, i’d rather say something like
Access Denied
)
r
I think this is the problem "An Authentication object was not found in the SecurityContext" Came across that problem earlier. Most suitable solution: Create a Custom GraphQL Directive which will handle authentication. This question popped up sometimes here and on GitHub Issues. Would be an option to document it in the spring sections of the docs maybe or code example https://github.com/ExpediaGroup/graphql-kotlin/issues/758 This will give you a 200 response and graphql-errors object with custom error message
d
I believe you could create custom
DataFetcherExceptionHandler
❤️ 1
b
DataFetcherExceptionHandler
might be the ticket, thanks