@@ -42,8 +42,6 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
4242 const result = await fn ( req as BitGoRequest < T > , res , next ) ;
4343 return res . sendEncoded ( result . type , result . payload ) ;
4444 } catch ( error ) {
45- logger . error ( 'Error in responseHandler:' , error ) ;
46-
4745 // If it's already a Response object (e.g. from Response.error)
4846 if ( error && typeof error === 'object' && 'type' in error && 'payload' in error ) {
4947 const apiError = error as ApiResponse ;
@@ -56,6 +54,7 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
5654 error : 'BitGoApiResponseError' ,
5755 details : apiError . result ,
5856 } ;
57+ logger . error ( JSON . stringify ( apiError . result , null , 2 ) ) ;
5958 return res . status ( apiError . status ) . json ( body ) ;
6059 }
6160
@@ -77,6 +76,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
7776 statusCode = 409 ;
7877 }
7978
79+ const errorBody = {
80+ name : error . name ,
81+ message : error . message ,
82+ stack : error . stack ,
83+ } ;
84+ // Log the error details for debugging
85+ logger . error ( JSON . stringify ( errorBody , null , 2 ) ) ;
8086 return res . sendEncoded ( statusCode , {
8187 error : error . message ,
8288 name : error . name ,
@@ -94,11 +100,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
94100 }
95101
96102 // Default error response
97- return res . sendEncoded ( 500 , {
103+ const errorBody = {
98104 error : 'Internal Server Error' ,
99105 name : error instanceof Error ? error . name : 'Error' ,
100106 details : error instanceof Error ? error . message : String ( error ) ,
101- } ) ;
107+ } ;
108+ logger . error ( JSON . stringify ( errorBody , null , 2 ) ) ;
109+ return res . sendEncoded ( 500 , errorBody ) ;
102110 }
103111 } ;
104112}
0 commit comments