A duct/ataraxy question.
• I have some middleware assigned against individual routes in config.edn
(i.e. at the :duct.router/ataraxy
level NOT the :duct.handler/root
level)
• That middleware works with the responses from the handler chain.
• Currently the responses are coming through to the middleware still wrapped up as ataraxy vectors - e.g. [:ataraxy.response/ok "some stuff"]
.
• I want to be dealing with raw status codes instead (e.g. {:status 200 :body "some stuff"}
)
So... how to do this?
I did look for a canonical mapping function in ataraxy to go between ataraxy statuses and integer status codes but what "mapping" there is is done using multimethods.
Any ideas?
Ok, so I've hacked together this solution for converting to an integer status:
(if (map? resp)
(:status resp)
(-> {:ataraxy/result [(first resp)]}
(ataraxy.handler/sync-default)
:status))
Obviously that incurs the overhead of running sync-default
twice. Also, it's relying on sync-default
having no side-effects. This doesn't seem to be the case (and I'd be surprised if there were side effects) but other folks can always create their own defmethod
that does have side effects. I can live with that caveat though.