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