error catch for NoSuchSession
This commit is contained in:
@@ -2,6 +2,7 @@ const logger = require("logops")
|
|||||||
, { By, until } = require('selenium-webdriver')
|
, { By, until } = require('selenium-webdriver')
|
||||||
, captcha = require('../component/CaptchaComp')
|
, captcha = require('../component/CaptchaComp')
|
||||||
, poolingService = require('../service/PoolingService')
|
, poolingService = require('../service/PoolingService')
|
||||||
|
const { NoSuchSessionError } = require("selenium-webdriver/lib/error")
|
||||||
|
|
||||||
|
|
||||||
class SeleniumBrowser {
|
class SeleniumBrowser {
|
||||||
@@ -19,6 +20,12 @@ class SeleniumBrowser {
|
|||||||
let html = await driver.get(uri)
|
let html = await driver.get(uri)
|
||||||
.then(() => driver.findElement(By.css('body')))
|
.then(() => driver.findElement(By.css('body')))
|
||||||
.then(body => body.getAttribute('innerHTML'))
|
.then(body => body.getAttribute('innerHTML'))
|
||||||
|
.catch(e => {
|
||||||
|
if (e instanceof NoSuchSessionError) {
|
||||||
|
this.pool.destroy(driver)
|
||||||
|
throw new NoSuchSessionError
|
||||||
|
}
|
||||||
|
})
|
||||||
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
|
||||||
if (this.pool.isBorrowedResource(driver)) this.pool.release(driver)
|
if (this.pool.isBorrowedResource(driver)) this.pool.release(driver)
|
||||||
|
|||||||
@@ -30,10 +30,9 @@ class PoolingService {
|
|||||||
|
|
||||||
destroy(driver) {
|
destroy(driver) {
|
||||||
logger.info('Quitting driver')
|
logger.info('Quitting driver')
|
||||||
this.pool.release(driver)
|
return this.pool.release(driver).then(() => driver.quit().catch(err => {
|
||||||
return driver.quit().catch(err => {
|
|
||||||
logger.debug({ message: err.message }, 'Quitting error')
|
logger.debug({ message: err.message }, 'Quitting error')
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(driver) {
|
validate(driver) {
|
||||||
|
|||||||
Reference in New Issue
Block a user