This commit is contained in:
spiduler
2020-10-21 23:41:56 +09:00
parent e8615cc26e
commit 7c604ed2a0
2 changed files with 12 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ const express = require("express")
, browser = require('./src/service/HeadlessService')
, port = 32101
, { NoSuchSessionError } = require("selenium-webdriver/lib/error")
// , { puppeteerErrors } = require("puppeteer-core/lib/cjs/puppeteer/common/Errors");
// , { puppeteerErrors } = require("puppeteer-core/lib/cjs/puppeteer/common/Errors");
logger.getContext = function getContext() {
@@ -63,10 +63,13 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
* request handler
*/
app.post('/', async (req, res, next) => {
browser.get(req.body).then(html => res.send(html)).catch(e => {
if(e instanceof NoSuchSessionError) {
browser.get(req.body).then(html => {
if (html) res.send(html)
else throw new Error('Emtpy html')
}).catch(e => {
if (e instanceof NoSuchSessionError) {
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
}else {
} else {
logger.error({ reason: e.message, url: req.url }, 'Browser error occured')
}
res.status(500).send({ code: 500, message: e.message })

View File

@@ -112,6 +112,10 @@ class SeleniumBrowser {
.then(html => {
this.pool.release(driver)
return html
}).catch(err => {
logger.error({message: err.message}, 'Wait element failed')
this.pool.release(driver)
return ''
})
} else {
this.pool.release(driver)