Skip to content

Commit

Permalink
test: handle proxy error message (#19319)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Feb 1, 2025
1 parent e28bce2 commit e8c783f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions playground/proxy-bypass/__tests__/proxy-bypass.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, vi } from 'vitest'
import { browserLogs, isServe, page, serverLogs } from '~utils'
import { browserLogs, page, serverLogs } from '~utils'

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

test.runIf(isServe)('async-proxy-bypass-with-error', async () => {
test('async-proxy-bypass-with-error', async () => {
await vi.waitFor(() => {
expect(serverLogs.join('\n')).toContain('bypass error')
})
Expand Down
14 changes: 14 additions & 0 deletions playground/proxy-bypass/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ export default defineConfig({
},
},
},
plugins: [
{
name: 'handle-error-in-preview',
configurePreviewServer({ config, middlewares }) {
return () => {
middlewares.use((err, _req, res, _next) => {
config.logger.error(err.message, { error: err })
res.statusCode = 500
res.end()
})
}
},
},
],
})

0 comments on commit e8c783f

Please sign in to comment.