From 91fe789e7c60cec732d4df98cb26165176cc7cbf Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Sun, 24 May 2020 01:12:10 +0200 Subject: one liner for some functions + pass the error to the body --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index ec91cb7..a307db8 100644 --- a/index.js +++ b/index.js @@ -86,15 +86,13 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive" }); await page.close(); } catch (error) { - if (!error.toString().includes("ERR_BLOCKED_BY_CLIENT")) - throw (error); + if (!error.toString().includes("ERR_BLOCKED_BY_CLIENT")) { + ctx.status = 500; + ctx.body = error; + } } - responseHeadersToRemove.forEach(header => { - delete responseHeaders[header]; - }); - Object.keys(responseHeaders).forEach(header => { - ctx.set(header, jsesc(responseHeaders[header])); - }); + responseHeadersToRemove.forEach(header => delete responseHeaders[header]); + Object.keys(responseHeaders).forEach(header => ctx.set(header, jsesc(responseHeaders[header]))); ctx.body = responseBody; } else { -- cgit v1.2.3