reitit

p-himik 2024-02-10T11:14:53.136099Z

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.

✅ 1
valerauko 2024-02-13T14:16:12.052059Z

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.

p-himik 2024-02-13T14:18:30.684529Z

I often use exceptions for HTTP 4xx errors, the exception middleware comes in handy here.

valerauko 2024-02-13T14:21:30.202079Z

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

valerauko 2024-02-13T14:22:08.905629Z

Though personally I prefer to use router scopes for authz checking

p-himik 2024-02-10T11:22:48.901789Z

Ah, muuntaja/format-middleware can be used as three separate middlewares, I see.

👍🏼 1