-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Copy link
Labels
feat: devdev serverdev server
Description
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
| 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: devdev serverdev server