fix(nuxt): hide unhandled error messages in prod (#28156)

This commit is contained in:
Daniel Roe 2024-07-17 12:13:56 +01:00 committed by GitHub
parent 4846dbf6f8
commit 42ef331816
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,