@@ -10,31 +10,30 @@ import {
1010 boldGreen ,
1111 green ,
1212 dimGray ,
13+ bold ,
1314} from './utils/console-colors' ;
1415import { centerText } from './utils' ;
16+ import { ErrorOptions , ErrorResponse } from './types' ;
17+
18+
1519
1620// Internal config object (optional override)
17- let errorOptions = {
21+ let errorOptions : ErrorOptions = {
1822 showStack :
1923 process . env . SHOW_STACK !== 'false' && process . env . NODE_ENV !== 'production' ,
2024 logError :
2125 process . env . LOG_ERROR !== 'false' && process . env . NODE_ENV !== 'production' ,
26+ introLine : `💥 Even the best code breaks sometimes! Let's debug...` ,
2227} ;
2328
24- export function setErrorOptions ( options : Partial < typeof errorOptions > ) {
29+ export function setErrorOptions ( options : Partial < ErrorOptions > ) {
2530 errorOptions = {
2631 ...errorOptions ,
2732 ...options ,
2833 } ;
2934}
3035
31- export interface ErrorResponse {
32- success : false ;
33- status : number ;
34- message : string ;
35- errorDetails ?: string | object | null ;
36- stack ?: string | string [ ] ;
37- }
36+
3837
3938export const globalErrorHandler = (
4039 err : unknown ,
@@ -75,7 +74,10 @@ export const globalErrorHandler = (
7574
7675 // Log the error if configured to do so
7776 if ( errorOptions . logError ) {
78- console . error ( `\n${ centerText ( dimGray ( 'Error Log' ) ) } \n` ) ;
77+
78+ if ( errorOptions . introLine ) {
79+ console . error ( `\n${ ( bold ( `${ errorOptions . introLine } ` ) ) } \n` ) ;
80+ }
7981
8082 // log the error status
8183 console . error (
@@ -117,7 +119,7 @@ export const globalErrorHandler = (
117119 if ( remainingCount > 0 ) {
118120 console . error (
119121 dimGray (
120- `...and ${ remainingCount } more lines. 💡 See full stack in error respons `
122+ `...and ${ remainingCount } more lines. 💡 See full stack in error response `
121123 )
122124 ) ;
123125 }
0 commit comments