cloudflare / node-cloudflare

Node.js API for Client API

Home Page:https://cloudflare.github.io/node-cloudflare/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retry API calls

naseemkullah opened this issue · comments

Occasionally we will get a bad request error from an api call to purge the cache. However upon retrying the same request immediately after, it succeeds.

Could a retry policy be implemented directly in the Cloudflare API?
For the zones.purgeCache in particular.

It would be possible to add, but not currently planned. I don't currently have any way to make most requests to the API idempotent, so it would be unsafe for me to do so automatically.

Sorry, I do not understand the need for idempotency if the API request is only to succeed once? The retry mechanism would only be upon failure of a request after all.

Is that to say there are requests that could be partially complete and then error out?

You use the package to submit a request. Most of the time it succeeds and we're all happy.

However it fails. Say your network gets disconnected, or you get a 502 from some HTTP proxy somewhere on Cloudflare's backend, you as the client (and me as the package author) have no way to know if it's been processed or not. Other API have idempotency guarantees (either that retries are safe, or using idempotency keys), but the Cloudflare API does not.

With that mind, it's not the right place for me to make the decision to retry or not.

I see, I see.
Could it be user configurable option that defaults to false/0 retries?

I plan on exposing this as part of the v3 API.