Skip to content

Commit d2f02a8

Browse files
authored
fix: return 500 on proxy error only if possible (fixes #9172) (#9175)
1 parent e6f3b02 commit d2f02a8

File tree

1 file changed

+7
-5
lines changed
  • packages/vite/src/node/server/middlewares

1 file changed

+7
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ export function proxyMiddleware(
5555
error: err
5656
}
5757
)
58-
res
59-
.writeHead(500, {
60-
'Content-Type': 'text/plain'
61-
})
62-
.end()
58+
if (!res.writableEnded) {
59+
res
60+
.writeHead(500, {
61+
'Content-Type': 'text/plain'
62+
})
63+
.end()
64+
}
6365
} else {
6466
config.logger.error(`${colors.red(`ws proxy error:`)}\n${err.stack}`, {
6567
timestamp: true,

0 commit comments

Comments
 (0)