Description
Instead of returning 500 when the upstream server in not available in the Vite dev server proxying, return 502 (Bad Gateway), which allows to detect this case more cleanly in frontend code and retry.
Suggested solution
Modify:
|
proxy.on('error', (err, _req, res) => { |
|
// When it is ws proxy, res is net.Socket |
|
if ('req' in res) { |
|
config.logger.error( |
|
`${colors.red(`http proxy error: ${res.req.url}`)}\n${err.stack}`, |
|
{ |
|
timestamp: true, |
|
error: err, |
|
}, |
|
) |
|
if (!res.headersSent && !res.writableEnded) { |
|
res |
|
.writeHead(500, { |
|
'Content-Type': 'text/plain', |
|
}) |
|
.end() |
|
} |
|
} else { |
|
config.logger.error(`${colors.red(`ws proxy error:`)}\n${err.stack}`, { |
|
timestamp: true, |
|
error: err, |
|
}) |
|
res.end() |
|
} |
|
}) |
To return 502 instead of 500, or maybe only for applicable error types.
Alternative
Check for and retry on 500, which is less accurate, and only fits for development mode
Additional context
No response
Validations
Description
Instead of returning 500 when the upstream server in not available in the Vite dev server proxying, return 502 (Bad Gateway), which allows to detect this case more cleanly in frontend code and retry.
Suggested solution
Modify:
vite/packages/vite/src/node/server/middlewares/proxy.ts
Lines 97 to 121 in 44b5bdf
To return 502 instead of 500, or maybe only for applicable error types.
Alternative
Check for and retry on 500, which is less accurate, and only fits for development mode
Additional context
No response
Validations