Skip to content

Commit

Permalink
fix(proxy): handle error when proxy itself errors (#13929)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaejunlee committed Jul 24, 2023
1 parent bf51ed4 commit 4848e41
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/vite/src/node/server/middlewares/proxy.ts
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

0 comments on commit 4848e41

Please sign in to comment.