@@ -11,6 +11,7 @@ import {
1111 ForbiddenError ,
1212 ConflictError ,
1313} from './errors' ;
14+ import logger from '../logger' ;
1415
1516// Extend Express Response to include sendEncoded
1617interface EncodedResponse extends ExpressResponse {
@@ -53,6 +54,7 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
5354 error : 'BitGoApiResponseError' ,
5455 details : apiError . result ,
5556 } ;
57+ logger . error ( JSON . stringify ( apiError . result , null , 2 ) ) ;
5658 return res . status ( apiError . status ) . json ( body ) ;
5759 }
5860
@@ -74,6 +76,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
7476 statusCode = 409 ;
7577 }
7678
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 ) ) ;
7786 return res . sendEncoded ( statusCode , {
7887 error : error . message ,
7988 name : error . name ,
@@ -91,11 +100,13 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
91100 }
92101
93102 // Default error response
94- return res . sendEncoded ( 500 , {
103+ const errorBody = {
95104 error : 'Internal Server Error' ,
96105 name : error instanceof Error ? error . name : 'Error' ,
97106 details : error instanceof Error ? error . message : String ( error ) ,
98- } ) ;
107+ } ;
108+ logger . error ( JSON . stringify ( errorBody , null , 2 ) ) ;
109+ return res . sendEncoded ( 500 , errorBody ) ;
99110 }
100111 } ;
101112}
0 commit comments