mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): hide unhandled error messages in prod (#28156)
This commit is contained in:
parent
4846dbf6f8
commit
42ef331816
@ -115,7 +115,13 @@ function normalizeError (error: any) {
|
|||||||
// temp fix for https://github.com/unjs/nitro/issues/759
|
// temp fix for https://github.com/unjs/nitro/issues/759
|
||||||
// TODO: investigate vercel-edge not using unenv pollyfill
|
// TODO: investigate vercel-edge not using unenv pollyfill
|
||||||
const cwd = typeof process.cwd === 'function' ? process.cwd() : '/'
|
const cwd = typeof process.cwd === 'function' ? process.cwd() : '/'
|
||||||
const stack = ((error.stack as string) || '')
|
|
||||||
|
// Hide details of unhandled/fatal errors in production
|
||||||
|
const hideDetails = !import.meta.dev && error.unhandled
|
||||||
|
|
||||||
|
const stack = hideDetails
|
||||||
|
? []
|
||||||
|
: ((error.stack as string) || '')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.splice(1)
|
.splice(1)
|
||||||
.filter(line => line.includes('at '))
|
.filter(line => line.includes('at '))
|
||||||
@ -135,9 +141,8 @@ function normalizeError (error: any) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const statusCode = error.statusCode || 500
|
const statusCode = error.statusCode || 500
|
||||||
const statusMessage =
|
const statusMessage = error.statusMessage ?? (statusCode === 404 ? 'Not Found' : '')
|
||||||
error.statusMessage ?? (statusCode === 404 ? 'Not Found' : '')
|
const message = hideDetails ? 'internal server error' : (error.message || error.toString())
|
||||||
const message = error.message || error.toString()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stack,
|
stack,
|
||||||
|
Loading…
Reference in New Issue
Block a user