Skip to content

Instantly share code, notes, and snippets.

@leosbotelho
Created August 30, 2022 20:01
Show Gist options
  • Save leosbotelho/6cc69aec616ea6646535aaa62f304ef9 to your computer and use it in GitHub Desktop.
Save leosbotelho/6cc69aec616ea6646535aaa62f304ef9 to your computer and use it in GitHub Desktop.
`got` and `ras` eg
import got from "got"
import { httpsReq_ } from "./got.mjs"
import { CgQ, got as ras_got } from "./ras.mjs"
const mkCgi = () =>
got.extend({
https: {
minVersion: "TLSv1.3"
},
request: httpsReq_(CgQ.add),
retry: ras_got.Cg.retry
})
import got from "got"
import { httpsReq_ } from "./got.mjs"
import { got as ras_got } from "./ras.mjs"
const mkTgi = f => {
const request_ = f === undefined ? {} : { request: httpsReq_(f) }
return got.extend({
https: {
minVersion: "TLSv1.3"
},
...request_,
retry: ras_got.Tg.retry,
hooks: {
afterResponse: [
(res, retry_) => {
if (res.statusCode !== 200) return res
try {
const resJson = JSON.parse(res.body)
// might be a partial success
const hasErrors = Object.hasOwn(resJson, "errors")
if (hasErrors || Object.hasOwn(resJson, "error"))
return retry_({})
} catch (e) {
return retry_({})
}
return res
}
]
}
})
}
@leosbotelho
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment