Hello,
We’re migrating some legacy services which have a bunch of http4s exception handlers, which I’ve been able to reproduce by configuring the handler in the Tapir http4s interpreter which has been great.
We’re now starting to move some endpoints over to using the oneOf
variant matchers, but this comes with the problem that oneOf
needs to be exhaustive, but I want to be able to handle a subset of the errors in Tapir (and generate the docs) but continue falling back for any unmapped errors.
The exception mapper is invoked, but with a Tapir exception complaining about non-exhaustive matches:
ExceptionContext(java.lang.IllegalArgumentException: None of the mappings defined in the one-of output: one of({body as application/json (UTF-8)} status code (401)|status code (403) {body as application/json (UTF-8)}), is applicable to the value: my.custom.Error$: bla. Verify that the type parameters to oneOf are correct, and that the oneOfVariants are exhaustive (that is, that they cover all possible
This is how we define the endpoints:
Route.authenticated
.in("some" / "route")
.in(jsonBody[ReqBodyObj])
.out(jsonBody[ResBodyObj])
// Route.authenticated specifies errorOut as 'AuthenticationError'
// Now, we specialise the error output
.errorOutVariant(oneOfVariant(statusCode(StatusCode.Forbidden).and(jsonBody[SpecialisedError])))
.serverLogicRecoverErrors { user => input =>
// Raise SomeRandomError that should be mapped without variants
Any way to subvert this would be greatly appreciated. It’s too large of an undertaking for me to convert every error in the exception mapper to oneOf
variants at the moment