@@ -9,33 +9,44 @@ type Input = {
99 language : Language ;
1010 code : string ;
1111} ;
12+
1213type Output = {
1314 output : string ;
1415 responseTime : number ; // in milliseconds
1516} ;
17+
1618export async function executeCodeAction ( input : Input ) : Promise < Output > {
1719 const start = performance . now ( ) ;
18- let responseTime = 0 ;
19- let end = 0 ;
20+
2021 try {
2122 const response = await axios . post ( `${ baseUri } /run` , input ) ;
22- end = performance . now ( ) ;
23- responseTime = end - start ;
23+ const end = performance . now ( ) ;
2424
2525 return {
2626 output : response . data . output ,
27- responseTime : Math . round ( responseTime ) ,
27+ responseTime : Math . round ( end - start ) ,
2828 } ;
29- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3029 } catch ( error : any ) {
31- end = performance . now ( ) ;
32- responseTime = end - start ;
30+ const end = performance . now ( ) ;
31+ const responseTime = Math . round ( end - start ) ;
3332
34- const errorMessage = error . response . data . details as unknown as string ;
35- const response = {
36- output : errorMessage ,
37- responseTime : Math . round ( responseTime ) ,
38- } ;
39- throw new Error ( JSON . stringify ( response ) ) ;
33+ // Safer extraction of error message
34+ const errorMessage =
35+ error ?. response ?. data ?. details || "Unknown error occurred" ;
36+
37+ // Optional: log more useful error info for debugging
38+ console . error ( "executeCodeAction Error:" , {
39+ message : errorMessage ,
40+ status : error ?. response ?. status ,
41+ data : error ?. response ?. data ,
42+ } ) ;
43+
44+ // Throw a serializable error object
45+ throw new Error (
46+ JSON . stringify ( {
47+ output : errorMessage ,
48+ responseTime,
49+ } )
50+ ) ;
4051 }
4152}
0 commit comments