fix(nitro): ensure ssr error statusCode is a number (#19001)

This commit is contained in:
Xin Du (Clark) 2023-02-13 22:55:29 +00:00 committed by GitHub
parent 54739e435e
commit 859fbd0add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -85,7 +85,7 @@ interface _NuxtApp {
rendered?: Function rendered?: Function
error?: Error | { error?: Error | {
url: string url: string
statusCode: string statusCode: number
statusMessage: string statusMessage: string
message: string message: string
description: string description: string

View File

@ -167,8 +167,13 @@ export default defineRenderHandler(async (event) => {
// Whether we're rendering an error page // Whether we're rendering an error page
const ssrError = event.node.req.url?.startsWith('/__nuxt_error') const ssrError = event.node.req.url?.startsWith('/__nuxt_error')
? getQuery(event) as Exclude<NuxtApp['payload']['error'], Error> ? getQuery(event) as unknown as Exclude<NuxtApp['payload']['error'], Error>
: null : null
if (ssrError && ssrError.statusCode) {
ssrError.statusCode = parseInt(ssrError.statusCode as any)
}
if (ssrError && event.node.req.socket.readyState !== 'readOnly' /* direct request */) { if (ssrError && event.node.req.socket.readyState !== 'readOnly' /* direct request */) {
throw createError('Cannot directly render error page!') throw createError('Cannot directly render error page!')
} }

View File

@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
it('default server bundle size', async () => { it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(stats.server.totalBytes).toBeLessThan(90000) expect(stats.server.totalBytes).toBeLessThan(90200)
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(modules.totalBytes).toBeLessThan(2700000) expect(modules.totalBytes).toBeLessThan(2700000)