berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.23k stars 732 forks source link

Expose `PuppeteerExtraPluginRecaptcha` error #741

Open markcellus opened 1 year ago

markcellus commented 1 year ago

Resolves https://github.com/berstend/puppeteer-extra/issues/740 by updating the PuppeteerExtraPluginRecaptcha thrown error and exposes all of its properties to be evaluated by consumer code.

markcellus commented 1 year ago

Perhaps a better way to do this is to create a new error class that extends Error (e.g. PuppeteerExtraPluginRecaptchaError) and just throw that. But I'm not too sure if that would be acceptable here.

berstend commented 1 year ago

Yeah, the error handling isn't optimal 😄 From a quick look it seems that a response.error can be a string or an Error (in which case wrapping it again in an error would cause the info to get lost)

I wonder if this would work as a fix as well:

if (this.opts.throwOnError && response.error) {
  throw !!response.error?.message ? response.error : new Error(response.error)
}