Fork me on GitHub
#reitit
<
2022-07-20
>
Dameon13:07:54

Hello, I was wondering if there was a default way to cause responses schemas coercions to fail if the response doesn’t match the schema. Primarily for development. I’m trying to make sure all of my API responses are standardized.

valtteri14:07:07

Hi, reitit has middleware for response-coercion . Can be found in many examples, e.g. https://github.com/metosin/reitit/tree/master/examples/just-coercion-with-ring

Dameon16:07:14

Strange, my configuration looks like the docs. Gotta look closer I guess.

valtteri19:07:14

Please let me know if you end up getting stuck and I’ll try to give more specific pointers and examples. 🙂

Dameon14:07:13

I think I figured it out, I hadn’t added the {:status 200} in the response map, but it was getting added somewhere later in the middleware or something so on the client it was getting a 200 which threw me off.

Dameon14:07:31

I was also wondering if it was possible to define defaults for all statuses, or for a level of status. All statuses between [400,500) get the same schema.

valtteri17:07:06

Everything is possible with a custom error handling middleware. 🙂 https://cljdoc.org/d/metosin/reitit/0.5.18/doc/ring/exception-handling-with-ring

Dameon15:09:11

@U6N4HSMFW thanks, these really helped 🙂

valtteri15:09:50

Nice to hear that you got forward with these. 🙂