oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
529 stars 44 forks source link

Throw an exception on status code >= 400 or :error #180

Closed fhalde closed 1 year ago

fhalde commented 1 year ago

What would be the right interceptor for this purpose? Should my interceptor return a tc/terminate or can it just throw an exception?

oliyh commented 1 year ago

Hi,

I think both are correct depending how you want the flow to work. For example, you could just terminate on a 404 with a nil body and do nothing with the result, but perhaps on a 400 or 500 you want to catch an exception and log or tell the user about it.

In both cases, the leave phase finishes. If you terminate then the interceptor chain stops immediately, if you throw an error then you will only process :error handles on your interceptor stack. This can be useful if you have things like metrics or logging early on which you still want to trigger.

Hope this helps

oliyh commented 1 year ago

Closing this for now, please let me know if you need any more help.

Cheers