Skip to content
Discussion options

You must be logged in to vote

Got validates options and doesn't allow arbitrary properties. To add custom properties, you have two options:

Option 1: Use the context object (recommended)

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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants