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,29 +115,34 @@ 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) || '')
|
|
||||||
.split('\n')
|
// Hide details of unhandled/fatal errors in production
|
||||||
.splice(1)
|
const hideDetails = !import.meta.dev && error.unhandled
|
||||||
.filter(line => line.includes('at '))
|
|
||||||
.map((line) => {
|
const stack = hideDetails
|
||||||
const text = line
|
? []
|
||||||
.replace(cwd + '/', './')
|
: ((error.stack as string) || '')
|
||||||
.replace('webpack:/', '')
|
.split('\n')
|
||||||
.replace('file://', '')
|
.splice(1)
|
||||||
.trim()
|
.filter(line => line.includes('at '))
|
||||||
return {
|
.map((line) => {
|
||||||
text,
|
const text = line
|
||||||
internal:
|
.replace(cwd + '/', './')
|
||||||
(line.includes('node_modules') && !line.includes('.cache')) ||
|
.replace('webpack:/', '')
|
||||||
line.includes('internal') ||
|
.replace('file://', '')
|
||||||
line.includes('new Promise'),
|
.trim()
|
||||||
}
|
return {
|
||||||
})
|
text,
|
||||||
|
internal:
|
||||||
|
(line.includes('node_modules') && !line.includes('.cache')) ||
|
||||||
|
line.includes('internal') ||
|
||||||
|
line.includes('new Promise'),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
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