From a78d361195827703053fc9b14a7affeaac77d0c8 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 1 Nov 2018 12:14:53 -0700 Subject: [PATCH] fix: avoid headers already sent error --- lib/proxy.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index 861fab3..15dca7f 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -27,9 +27,11 @@ function proxy (state, { target }) { onError (error, request, response) { /* istanbul ignore if */ if (error.message.indexOf('Nock: No match for request') !== 0) { - response.writeHead(404, { - 'Content-Type': 'application/json; charset=utf-8' - }) + if (!response.headerSent) { + response.writeHead(500, { + 'Content-Type': 'application/json; charset=utf-8' + }) + } return response.end(JSON.stringify({ error: error.message