cloudflare icon indicating copy to clipboard operation
cloudflare copied to clipboard

Expose it as got decorator

Open Kikobeats opened this issue 5 years ago • 0 comments

Hello,

Do you think could be possible to expose a more affordable interface in order to make it easy to accommodate any project using got?

This is the thing I have on mind:

const got = require('@ctrl/cloudflare')(require('got')

Internally it can do the thing suggested on the readme:

const decorator = got = async (...opts) => {
  let res

  try {
    res = await got(...opts);
  } catch (error) {
    res = await catchCloudflare(error, ...opts);
  }

  if (res) return res
  throw error
}

In fact, that could be a good moment to create cookieJar is it isn't been passed as a parameter.

Feeling something like this could reduce the friction of adopting the library a lot. Thoughts? 🙂

Kikobeats avatar Feb 23 '20 14:02 Kikobeats