-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perform the error handling for raise_request_on_failer
before waiting for selectors / functions
#202
base: main
Are you sure you want to change the base?
Perform the error handling for raise_request_on_failer
before waiting for selectors / functions
#202
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,28 @@ const path = require('path'); | |
const _processPage = (async (convertAction, urlOrHtml, options) => { | ||
let browser, errors = [], tmpDir; | ||
|
||
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; | ||
Comment on lines
+34
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could move this up outside of this function |
||
|
||
if (errors.length > 0) { | ||
throw new RequestFailedError(errors); | ||
} | ||
} | ||
|
||
try { | ||
// Configure puppeteer debugging options | ||
const debug = options.debug; delete options.debug; | ||
|
@@ -34,24 +56,24 @@ const _processPage = (async (convertAction, urlOrHtml, options) => { | |
args: process.env.GROVER_NO_SANDBOX === 'true' ? ['--no-sandbox', '--disable-setuid-sandbox'] : [], | ||
userDataDir: tmpDir | ||
}; | ||
|
||
if (typeof debug === 'object' && !!debug) { | ||
if (debug.headless !== undefined) { launchParams.headless = debug.headless; } | ||
if (debug.devtools !== undefined) { launchParams.devtools = debug.devtools; } | ||
} | ||
|
||
// Configure additional launch arguments | ||
const args = options.launchArgs; delete options.launchArgs; | ||
if (Array.isArray(args)) { | ||
launchParams.args = launchParams.args.concat(args); | ||
} | ||
|
||
// Set executable path if given | ||
const executablePath = options.executablePath; delete options.executablePath; | ||
if (executablePath) { | ||
launchParams.executablePath = executablePath; | ||
} | ||
|
||
// Launch the browser and create a page | ||
browser = await puppeteer.launch(launchParams); | ||
} | ||
|
@@ -172,6 +194,8 @@ const _processPage = (async (convertAction, urlOrHtml, options) => { | |
await page.goto(displayUrl || 'http://example.com', requestOptions); | ||
} | ||
|
||
handleErrors(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that the opposite also needs to hold true. ie if the It looks like if we checked for errors right away AND after the delayed checks it should resolve your use case whilst still allowing the behaviour to retain it's existing function. |
||
|
||
// add styles (if provided) | ||
const styleTagOptions = options.styleTagOptions; delete options.styleTagOptions; | ||
if (Array.isArray(styleTagOptions)) { | ||
|
@@ -232,23 +256,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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not so sure about this method name..
handleErrors
is a little nondescript. MaybehandleRequestErrors
?the
errors
variable probably should have been named in a similar fashion!