Skip to content

Commit

Permalink
fix: proxy non-200 http responses
Browse files Browse the repository at this point in the history
Transfer errors responses from the proxied server, including the status code, to the client.

Fixes gatsbyjs#36589, aka gatsbyjs#34244, aka gatsbyjs#33333.
  • Loading branch information
jsalvata committed Oct 3, 2022
1 parent 569b5dc commit 4327f39
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`

Expand Down

0 comments on commit 4327f39

Please sign in to comment.