From 21dc7769ab80a53eb486023222d85fe8d875463e Mon Sep 17 00:00:00 2001 From: Jordi Salvat i Alabart Date: Sun, 11 Sep 2022 15:12:41 +0200 Subject: [PATCH] fix: proxy non-200 http responses Transfer errors responses from the proxied server, including the status code, to the client. Fixes https://github.com/gatsbyjs/gatsby/issues/36589, aka https://github.com/gatsbyjs/gatsby/issues/34244, aka https://github.com/gatsbyjs/gatsby/issues/33333. --- packages/gatsby/src/utils/start-server.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/src/utils/start-server.ts b/packages/gatsby/src/utils/start-server.ts index e6b3270a5b1fd..0255fc627d706 100644 --- a/packages/gatsby/src/utils/start-server.ts +++ b/packages/gatsby/src/utils/start-server.ts @@ -561,8 +561,9 @@ export async function startServer( res.writeHead(response.statusCode || 200, response.headers) ) .on(`error`, (err, _, response) => { - if (response) { + if (response = err.response) { res.writeHead(response.statusCode || 400, response.headers) + res.end(response.rawBody) } else { const message = `Error when trying to proxy request "${req.originalUrl}" to "${proxiedUrl}"`