use message failure responses - #7787
ivan-klass wants to merge 1 commit into
Conversation
4a33812 to
a23316c
Compare
| badRequest.covary[F] | ||
| .recover { | ||
| case Parser.HeaderP.ParseHeadersError(_) => badRequest.covary[F] | ||
| case mf: MessageFailure => mf.toHttpResponse[F](req.httpVersion) |
There was a problem hiding this comment.
Have you tried using org.http4s.server.middleware.ErrorHandling? It's usually the standard way to add error handling to your server
There was a problem hiding this comment.
btw, speaking of the Blaze implementation, I'm not sure whether Blaze specifically handles MessageFailure internally. What particular difference in behavior are you seeing?
There was a problem hiding this comment.
@danicheg in tapir we're testing different backends (interpreters) for both server and clients.
In tapir http endpoints are described in special DSL types. There are scala types for payload format - e.g. json, form, multipart. Later special typeclasses (like sttp.tapir.Codec) will be provided by corresponding integration modules (say, something like "tapir-http4-circe").
So, by using a http4s interpreter, the list of implemented tapir endpoints becomes a http4s.HttpApp that can be mounted to the http4s server, and some kind of default server config is used in tests. I'm trying to switch all Blaze to Ember in all the tests and examples.
For different interpreters there are tests for invalid client payloads, specifically for bad request status if It's a bad multipart or json format.
It uses EntityEncoders under the hood for http4s.
It looks like these tests are not passing because the logic provided by the PR is missing in Ember http app mounting, compared to Blaze
There was a problem hiding this comment.
@danicheg I've found that in Blaze builder defaults the
DefaultServiceErrorHandler is used
which handles message failures (see here).
May we have something similar in EmberServerBuilder.Defaults.errorHandler ?
The problem is that we don't have request.httpVersion at hand, it's only Throwable as input.
There was a problem hiding this comment.
Have you tried to override the default error handler in the server builder (using org.http4s.ember.server.EmberServerBuilder#withErrorHandler)?
I'm trying to migrate tapir http4s server examples and tests from blaze to ember here.
It seems that in ember the handling of MessageFailure is missing