Skip to content

Commit

Permalink
fix: avoid headers already sent error
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 1, 2018
1 parent 7a8344c commit db3b1e4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db3b1e4

Please sign in to comment.