destroy session for all error

This commit is contained in:
spiduler
2021-01-18 12:13:59 +09:00
parent 8c6616c8bd
commit cb7da3daf3
2 changed files with 3 additions and 9 deletions

View File

@@ -66,11 +66,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
*/
app.post('/', async (req, res, next) => {
browser.get(req.body).then(html => res.send(html)).catch(e => {
if (e instanceof NoSuchSessionError) {
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')
}
logger.error({ message: e.message, info: e.info }, 'Browser error')
res.status(500).send({ code: 500, message: e.message })
})
})

View File

@@ -21,10 +21,8 @@ class SeleniumBrowser {
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.catch(e => {
if (e instanceof NoSuchSessionError) {
this.pool.destroy(driver)
throw new NoSuchSessionError
}
this.pool.destroy(driver)
throw new Error(e.message)
})
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver, this.pool) : this.getHtml(driver, html, params)
html = await p