-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development proxy doesn't return response body for 400 (4xx) status code #33333
Comments
I'm having something similar here. One of my APIs returns multiple status codes depending on the business logic validation, and everything is being converted to Gatsby version |
Gatsby previously depends on I'm currently using this post-install script as a temporary fix. const { readFile, writeFile } = require('fs/promises')
// temporary fix for start-server.js
{
const file = `${ __dirname }/../node_modules/gatsby/dist/utils/start-server.js`
readFile(file, 'utf-8').then(content => writeFile(
file,
content
.replace('if (response) {', 'if (response = err.response) {')
.replace(
'res.writeHead(response.statusCode || 400, response.headers);',
`res.writeHead(response.statusCode || 400, response.headers), res.end(response.rawBody);`,
),
))
} |
Hi! I'm closing this as a stale issue as in the meantime Gatsby 4 and related packages were released. You can check our Framework Version Support Page to see which versions currently receive active support. If this is a feature request, please create a discussion as we moved feature requests from issues to GitHub Discussions. Please try the mentioned issue on the latest version (using the Thanks! |
Transfer errors responses from the proxied server, including the status code, to the client. Fixes gatsbyjs#36589, aka gatsbyjs#34244, aka gatsbyjs#33333.
Transfer errors responses from the proxied server, including the status code, to the client. Fixes gatsbyjs#36589, aka gatsbyjs#34244, aka gatsbyjs#33333.
Transfer errors responses from the proxied server, including the status code, to the client. Fixes gatsbyjs#36589, aka gatsbyjs#34244, aka gatsbyjs#33333.
Preliminary Checks
Description
This happens after upgrading to Gatsby 3.14.0 which depends on
got
11.8.2.The
error
event no longer has response as the third parameter. It's now a property of the error object.gatsby/packages/gatsby/src/utils/start-server.ts
Line 505 in 5196e40
The
error.response
has.body
and.rawBody
, which possibly means that response body has already been consumed so piping just doesn't work as well. The fix is tores.end(response.rawBody)
on error.gatsby/packages/gatsby/src/utils/start-server.ts
Line 516 in 5196e40
Reproduction Link
https://codesandbox.io/s/infallible-phoebe-69w1t?file=/src/pages/index.js
Steps to Reproduce
proxy
ingatsby-config.js
yarn develop
https://run.mocky.io/v3/99fc1661-4a34-4334-a123-ae9c02b33db4
which has 400 status code and{"error":1}
response body.Expected Result
Should receive 400 {"error":1}
Actual Result
Received 500 Internal Server Error
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: