puppeteer-extra
puppeteer-extra copied to clipboard
[Bug] Type mismatch when throwing error
Describe the bug
When setting throwOnError to true, plugnin thwows response.error object as a string message,
index.cjs.js:811:13
console.warn('PuppeteerExtraPluginRecaptcha: An error occured during "getRecaptchaSolutions":', response.error);
output:
PuppeteerExtraPluginRecaptcha: An error occured during "getRecaptchaSolutions": {
_vendor: 'recaptcha',
provider: '2captcha',
id: 'eoajizvv30ew',
requestAt: 2021-02-07T11:20:16.352Z,
error: 'Error: 2captcha error: Missing response data: undefined'
}
So, response.error is an object.
index.cjs.js:813:9
if (this.opts.throwOnError && response.error) {
throw new Error(response.error); // There you sending Object as a String
}
And when we capturing an error we get this:
Error: Error: [object Object]
at PuppeteerExtraPluginRecaptcha.solveRecaptchas ( ...... /node_modules/puppeteer-extra-plugin-recaptcha/dist/index.cjs.js:869:19)
You need own Error, for example:
class PuppeteerExtraPluginRecaptchaError extends Error {
constructor(message, data) {
super(message);
this.name = this.constructor.name;
this.data = data;
}
}
and change this
if (this.opts.throwOnError && response.error) {
throw new Error(response.error);
}
to that
if (response && response.error && this.opts.throwOnError ) {
throw new PuppeteerExtraPluginRecaptchaError(response.error.error, response.error);
}
all over the code