How are you supposed to use reitit.ring.middleware.muuntaja/format-middleware and reitit.ring.middleware.exception/create-exception-middleware together?
If I order them in the order they're mentioned, the exception middleware doesn't wrap any Muuntaja errors.
If I reverse the order, responses produced by the exception middleware aren't processed by Muuntaja.
It seems as if for requests, the order should be reversed, but for responses it should be as is.
I usually have the formatter inside the exception catcher, because the latter is for really edge cases. The exception handler has an emergency-respond function that sets the content-type header and returns a valid json encoded response as a byte sequence in the body.
I often use exceptions for HTTP 4xx errors, the exception middleware comes in handy here.
Oh yeah, if it's expected then I'd have one middleware for those inside the formatter, and one for 500 omg end of the world errors outside the formatter
Though personally I prefer to use router scopes for authz checking
Ah, muuntaja/format-middleware can be used as three separate middlewares, I see.