Skip to content
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

fix(proxy): handle error when proxy itself errors #13929

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ export function proxyMiddleware(

proxy.on('error', (err, req, originalRes) => {
// When it is ws proxy, res is net.Socket
const res = originalRes as http.ServerResponse | net.Socket
if ('req' in res) {
// originalRes can be falsy if the proxy itself errored
const res = originalRes as http.ServerResponse | net.Socket | undefined
if (!res) {
config.logger.error(
`${colors.red(`http proxy error: ${err.message}`)}\n${err.stack}`,
{
timestamp: true,
error: err,
},
)
} else if ('req' in res) {
config.logger.error(
`${colors.red(`http proxy error at ${originalRes.req.url}:`)}\n${
err.stack
Expand Down