destroy session for all error
This commit is contained in:
6
index.js
6
index.js
@@ -66,11 +66,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
|
|||||||
*/
|
*/
|
||||||
app.post('/', async (req, res, next) => {
|
app.post('/', async (req, res, next) => {
|
||||||
browser.get(req.body).then(html => res.send(html)).catch(e => {
|
browser.get(req.body).then(html => res.send(html)).catch(e => {
|
||||||
if (e instanceof NoSuchSessionError) {
|
logger.error({ message: e.message, info: e.info }, 'Browser error')
|
||||||
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
|
|
||||||
} else {
|
|
||||||
logger.error(Object.assign({ message: e.message }, { info: e.info }), 'Browser error occured')
|
|
||||||
}
|
|
||||||
res.status(500).send({ code: 500, message: e.message })
|
res.status(500).send({ code: 500, message: e.message })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ class SeleniumBrowser {
|
|||||||
.then(() => driver.findElement(By.css('body')))
|
.then(() => driver.findElement(By.css('body')))
|
||||||
.then(body => body.getAttribute('innerHTML'))
|
.then(body => body.getAttribute('innerHTML'))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
if (e instanceof NoSuchSessionError) {
|
|
||||||
this.pool.destroy(driver)
|
this.pool.destroy(driver)
|
||||||
throw new NoSuchSessionError
|
throw new Error(e.message)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver, this.pool) : this.getHtml(driver, html, params)
|
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver, this.pool) : this.getHtml(driver, html, params)
|
||||||
html = await p
|
html = await p
|
||||||
|
|||||||
Reference in New Issue
Block a user