Skip to content

Commit e8c783f

Browse files
authoredFeb 1, 2025··
test: handle proxy error message (#19319)
1 parent e28bce2 commit e8c783f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

‎playground/proxy-bypass/__tests__/proxy-bypass.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, vi } from 'vitest'
2-
import { browserLogs, isServe, page, serverLogs } from '~utils'
2+
import { browserLogs, page, serverLogs } from '~utils'
33

44
test('proxy-bypass', async () => {
55
await vi.waitFor(() => {
@@ -12,7 +12,7 @@ test('async-proxy-bypass', async () => {
1212
expect(content).toContain('Hello after 4 ms (async timeout)')
1313
})
1414

15-
test.runIf(isServe)('async-proxy-bypass-with-error', async () => {
15+
test('async-proxy-bypass-with-error', async () => {
1616
await vi.waitFor(() => {
1717
expect(serverLogs.join('\n')).toContain('bypass error')
1818
})

‎playground/proxy-bypass/vite.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ export default defineConfig({
3030
},
3131
},
3232
},
33+
plugins: [
34+
{
35+
name: 'handle-error-in-preview',
36+
configurePreviewServer({ config, middlewares }) {
37+
return () => {
38+
middlewares.use((err, _req, res, _next) => {
39+
config.logger.error(err.message, { error: err })
40+
res.statusCode = 500
41+
res.end()
42+
})
43+
}
44+
},
45+
},
46+
],
3347
})

0 commit comments

Comments
 (0)
Please sign in to comment.