Arnab
07/25/2022, 10:35 AMLensFailure
for the graphQL module. The following is the code for the graphQL handler:
fun <T> graphQL(handler: GraphQLWithContextHandler<T>,
getContext: (Request) -> T,
badRequestFn: (LensFailure) -> Response = { Response(BAD_REQUEST) }
): RoutingHttpHandler = routes(POST to {
try {
Response(OK).with(responseLens of handler(requestLens(it), getContext(it)))
} catch (e: LensFailure) {
badRequestFn(e)
}
})
How do I throw an error in my graphql handlers in such a way that the badRequestFn
can process it? Is it not possible to throw my own custom Exceptions directly or do I need to wrap them somehow so they become a LensFailure
type?Arnab
07/25/2022, 10:38 AMException
type rather than LensFailure
but I’m hoping to leverage the library first and foremost 🙂dave
07/25/2022, 1:29 PMArnab
07/27/2022, 2:25 PMobject CatchAllGraphQLExceptionsFilter {
operator fun invoke(exceptionHandler: ExceptionHandler): Filter = Filter { next ->
{
try {
next(it)
} catch (e: Exception) {
exceptionHandler(e)
}
}
}
}
...
"/graphql" bind POST to CatchAllGraphQLExceptionsFilter(baseExceptionHandler).then(
graphQL(
BaseHandler,
::contextFnGithub
)
)