How make custom props when got.extend? #2291
-
|
For example(taken from hooman): const instance = got.extend({
cookieJar,
retry: {
limit: 2,
statusCodes: [408, 413, 429, 500, 502, 504, 521, 522, 524],
},
cloudflareRetry: 5,
notFoundRetry: 1,
captchaRetry: 1
onCaptcha: null,
captchaKey: process.env.HOOMAN_CAPTCHA_KEY,
rucaptcha: process.env.HOOMAN_RUCAPTCHA
}So i got an error: Unexpected option: cloudflareRetry |
Beta Was this translation helpful? Give feedback.
Answered by
sindresorhus
Oct 11, 2025
Replies: 1 comment
-
|
Got validates options and doesn't allow arbitrary properties. To add custom properties, you have two options: Option 1: Use the const instance = got.extend({
cookieJar,
retry: {
limit: 2,
statusCodes: [408, 413, 429, 500, 502, 504, 521, 522, 524]
},
context: {
cloudflareRetry: 5,
notFoundRetry: 1,
captchaRetry: 1,
onCaptcha: null,
captchaKey: process.env.HOOMAN_CAPTCHA_KEY,
rucaptcha: process.env.HOOMAN_RUCAPTCHA
}
});
// Access them via options.context in hooks
instance.extend({
hooks: {
beforeRequest: [
(options) => {
console.log(options.context.cloudflareRetry); // 5
}
]
}
});Option 2: Attach properties directly to the instance const instance = got.extend({
cookieJar,
retry: {
limit: 2,
statusCodes: [408, 413, 429, 500, 502, 504, 521, 522, 524]
}
});
// Add custom properties after creation
instance.cloudflareRetry = 5;
instance.notFoundRetry = 1;
instance.captchaRetry = 1;The |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sindresorhus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got validates options and doesn't allow arbitrary properties. To add custom properties, you have two options:
Option 1: Use the
contextobject (recommended)Option 2: Attach properties directly to the…