From fd3d3008d35712913af011891925089b0b50a577 Mon Sep 17 00:00:00 2001 From: Jens Claes Date: Mon, 10 May 2021 12:26:40 +0200 Subject: [PATCH] fix: catch errors on socket.write --- lib/http-proxy/passes/ws-incoming.js | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index 14da47103..92ca9e544 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -112,8 +112,12 @@ module.exports = { proxyReq.on('response', function (res) { // if upgrade event isn't going to happen, close the socket if (!res.upgrade && !socket.destroyed) { - socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers)); - res.pipe(socket); + try { + socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers)); + res.pipe(socket); + } catch (error) { + console.error(error) + } } }); diff --git a/package.json b/package.json index b8331cbe1..297a292a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@datacamp/http-proxy", - "version": "1.18.2", + "version": "1.18.3", "repository": { "type": "git", "url": "https://github.com/datacamp-engineering/node-http-proxy.git"