From 7c936ab8327f80341c167a10e8bc72f8ed2add4c Mon Sep 17 00:00:00 2001 From: Manuel Astudillo Date: Wed, 18 Sep 2024 12:36:08 +0200 Subject: [PATCH] fix: better error handling --- lib/proxy.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/proxy.ts b/lib/proxy.ts index 6b4cdae..e637475 100755 --- a/lib/proxy.ts +++ b/lib/proxy.ts @@ -229,10 +229,15 @@ export class Redbird { // // Send a 500 http status if headers have been sent // - if (err.code === 'ECONNREFUSED') { - res.writeHead && res.writeHead(502); - } else if (!res.headersSent) { - res.writeHead && res.writeHead(500, err.message, { 'content-type': 'text/plain' }); + if (!res || !res.writeHead) { + this.log?.error(err, 'Proxy Error'); + return; + } else { + if (err.code === 'ECONNREFUSED') { + res.writeHead(502); + } else if (!res.headersSent) { + res.writeHead(500, err.message, { 'content-type': 'text/plain' }); + } } //