Created
August 30, 2022 20:01
-
-
Save leosbotelho/6cc69aec616ea6646535aaa62f304ef9 to your computer and use it in GitHub Desktop.
`got` and `ras` eg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
] | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sindresorhus/got; ras