https://kotlinlang.org logo
Title
b

Brian Dilley

03/26/2021, 6:46 AM
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

Robert

03/26/2021, 10:11 AM
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

Dariusz Kuc

03/26/2021, 12:45 PM
I believe you could create custom
DataFetcherExceptionHandler
❤️ 1
b

Brian Dilley

03/26/2021, 7:03 PM
DataFetcherExceptionHandler
might be the ticket, thanks