@@ -55,33 +55,41 @@ export function isJsonRequest(event: H3Event) {
5555 ) ;
5656}
5757
58- export function normalizeError ( error : any ) {
58+ export function normalizeError ( error : any , isDev ?: boolean ) {
5959 // temp fix for https://github.com/unjs/nitro/issues/759
6060 // TODO: investigate vercel-edge not using unenv pollyfill
6161 const cwd = typeof process . cwd === "function" ? process . cwd ( ) : "/" ;
62- const stack = ( ( error . stack as string ) || "" )
63- . split ( "\n" )
64- . splice ( 1 )
65- . filter ( ( line ) => line . includes ( "at " ) )
66- . map ( ( line ) => {
67- const text = line
68- . replace ( cwd + "/" , "./" )
69- . replace ( "webpack:/" , "" )
70- . replace ( "file://" , "" )
71- . trim ( ) ;
72- return {
73- text,
74- internal :
75- ( line . includes ( "node_modules" ) && ! line . includes ( ".cache" ) ) ||
76- line . includes ( "internal" ) ||
77- line . includes ( "new Promise" ) ,
78- } ;
79- } ) ;
62+
63+ // Hide details of unhandled/fatal errors in production
64+ const hideDetails = ! isDev && ( error . unhandled || error . fatal ) ;
65+
66+ const stack = hideDetails
67+ ? [ ]
68+ : ( ( error . stack as string ) || "" )
69+ . split ( "\n" )
70+ . splice ( 1 )
71+ . filter ( ( line ) => line . includes ( "at " ) )
72+ . map ( ( line ) => {
73+ const text = line
74+ . replace ( cwd + "/" , "./" )
75+ . replace ( "webpack:/" , "" )
76+ . replace ( "file://" , "" )
77+ . trim ( ) ;
78+ return {
79+ text,
80+ internal :
81+ ( line . includes ( "node_modules" ) && ! line . includes ( ".cache" ) ) ||
82+ line . includes ( "internal" ) ||
83+ line . includes ( "new Promise" ) ,
84+ } ;
85+ } ) ;
8086
8187 const statusCode = error . statusCode || 500 ;
8288 const statusMessage =
8389 error . statusMessage ?? ( statusCode === 404 ? "Not Found" : "" ) ;
84- const message = error . message || error . toString ( ) ;
90+ const message = hideDetails
91+ ? "internal server error"
92+ : error . message || error . toString ( ) ;
8593
8694 return {
8795 stack,
0 commit comments