Skip to content

Commit 4848e41

Browse files
authored
fix(proxy): handle error when proxy itself errors (#13929)
1 parent bf51ed4 commit 4848e41

File tree

1 file changed

+11
-2
lines changed
  • packages/vite/src/node/server/middlewares

1 file changed

+11
-2
lines changed

packages/vite/src/node/server/middlewares/proxy.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,17 @@ export function proxyMiddleware(
5252

5353
proxy.on('error', (err, req, originalRes) => {
5454
// When it is ws proxy, res is net.Socket
55-
const res = originalRes as http.ServerResponse | net.Socket
56-
if ('req' in res) {
55+
// originalRes can be falsy if the proxy itself errored
56+
const res = originalRes as http.ServerResponse | net.Socket | undefined
57+
if (!res) {
58+
config.logger.error(
59+
`${colors.red(`http proxy error: ${err.message}`)}\n${err.stack}`,
60+
{
61+
timestamp: true,
62+
error: err,
63+
},
64+
)
65+
} else if ('req' in res) {
5766
config.logger.error(
5867
`${colors.red(`http proxy error at ${originalRes.req.url}:`)}\n${
5968
err.stack

0 commit comments

Comments
 (0)