clj-http

2025-01-22T13:32:40.320279Z

Can I pass :retry-handler fn inside a client/request req-map? or I need to build a custom http client?

2025-01-22T16:24:31.508049Z

Why my :retry-handler is not being called when I get 400?

2025-01-22T16:24:49.961319Z

is it because 400 is not an IOException?

lukasz 2025-01-22T16:39:05.181189Z

clj-https retry handler doesn't retry on 400s, it's only called on IOException type errors (socket timeouts and such). IIRC, even when you set :throw-exceptions true the retry handler won't be called. Depending on your needs, you can hook into the client builder and supply your own implementation of the retry strategy interface

2025-01-22T16:43:00.120519Z

yeah, got it. I would prefer to define retry strategies on client builder than to use an external macro or https://github.com/sunng87/diehard or https://github.com/BrunoBonacci/safely

2025-01-22T16:43:24.127219Z

what do you prefer? @lukaszkorecki?

lukasz 2025-01-22T16:44:23.792509Z

Yeah, same - I've created an internal http client, which wraps clj-http and integrated it with https://github.com/potetm/fusebox to handle retries and such

👍 1
2025-01-22T16:53:46.039569Z

:http-builder-fns
             [(fn [builder req]
                (clj-http.core/add-retry-handler builder (fn [e cnt context]
                                                             (def _e e))))]
is this the right path?

lukasz 2025-01-22T16:58:01.610069Z

Hm, I did it differently - the wrapper ensures that clj-http never throws on 500 status and below. Then it uses Fusebox to decide when to retry a request, based on the response, or type of exception - basically, it allows retries for 'bad' HTTP statuses, and if an exception is thrown it doesn't retry and re-throws the exception as that's in our case an unrecoverable error. Unfortunately I cannot easily share the code, it's quite specific to my team's setup in quite a few places.

2025-01-22T17:03:15.989909Z

yeah yeah no worriess

2025-01-22T17:03:24.198259Z

got to ask if I was in the right direction only

2025-01-22T17:03:35.148239Z

thanks @lukaszkorecki 😄

2025-01-22T17:04:14.635719Z

I'll take a look on it's usages and go beyond

lukasz 2025-01-22T17:04:14.800289Z

I'll be revising the retry layer soon actually, so might report back - I contributed changes to Fusebox recently and adopting them would simplify some things, so I'll look into this part as well

2025-01-22T17:04:16.950049Z

thanks 😄