diff --git a/lib/grover/js/processor.cjs b/lib/grover/js/processor.cjs index 3604f2e..678d9f5 100644 --- a/lib/grover/js/processor.cjs +++ b/lib/grover/js/processor.cjs @@ -29,6 +29,28 @@ const path = require('path'); const _processPage = (async (convertAction, urlOrHtml, options) => { let browser, page, errors = [], tmpDir, wsConnection = false; + const handleErrors = () => { + + function RequestFailedError(errors) { + this.name = "RequestFailedError"; + this.message = errors.map(e => { + if (e.failure()) { + return e.failure().errorText + " at " + e.url(); + } else if (e.response() && e.response().status()) { + return e.response().status() + " " + e.url(); + } else { + return "UnknownError " + e.url() + } + }).join("\n"); + } + + RequestFailedError.prototype = Error.prototype; + + if (errors.length > 0) { + throw new RequestFailedError(errors); + } + } + try { // Configure puppeteer debugging options const debug = options.debug; delete options.debug; @@ -195,6 +217,8 @@ const _processPage = (async (convertAction, urlOrHtml, options) => { await page.goto(displayUrl || 'http://example.com', requestOptions); } + handleErrors(); + // add styles (if provided) const styleTagOptions = options.styleTagOptions; delete options.styleTagOptions; if (Array.isArray(styleTagOptions)) { @@ -255,23 +279,6 @@ const _processPage = (async (convertAction, urlOrHtml, options) => { await page.hover(hoverSelector); } - if (errors.length > 0) { - function RequestFailedError(errors) { - this.name = "RequestFailedError"; - this.message = errors.map(e => { - if (e.failure()) { - return e.failure().errorText + " at " + e.url(); - } else if (e.response() && e.response().status()) { - return e.response().status() + " " + e.url(); - } else { - return "UnknownError " + e.url() - } - }).join("\n"); - } - RequestFailedError.prototype = Error.prototype; - throw new RequestFailedError(errors); - } - // Setup conversion timeout if (options.convertTimeout !== undefined) { options.timeout = options.convertTimeout;