@@ -5,6 +5,8 @@ import zodToJsonSchema from 'zod-to-json-schema';
55import { ApifyClient } from '../apify-client.js' ;
66import { HelperTools } from '../const.js' ;
77import type { InternalTool , ToolEntry } from '../types.js' ;
8+ import { ApifyApiError } from 'apify-client' ;
9+ import log from '@apify/log' ;
810
911const ajv = new Ajv ( { coerceTypes : 'array' , strict : false } ) ;
1012
@@ -38,6 +40,9 @@ export const getActorRun: ToolEntry = {
3840 }
3941 const client = new ApifyClient ( { token : apifyToken } ) ;
4042 const v = await client . run ( parsed . runId ) . get ( ) ;
43+ if ( ! v ) {
44+ return { content : [ { type : 'text' , text : `Run with ID '${ parsed . runId } ' not found.` } ] } ;
45+ }
4146 return { content : [ { type : 'text' , text : JSON . stringify ( v ) } ] } ;
4247 } ,
4348 } as InternalTool ,
@@ -99,8 +104,16 @@ export const abortActorRun: ToolEntry = {
99104 return { content : [ { type : 'text' , text : 'Run ID is required.' } ] } ;
100105 }
101106 const client = new ApifyClient ( { token : apifyToken } ) ;
102- const v = await client . run ( parsed . runId ) . abort ( { gracefully : parsed . gracefully } ) ;
103- return { content : [ { type : 'text' , text : JSON . stringify ( v ) } ] } ;
107+ try {
108+ const v = await client . run ( parsed . runId ) . abort ( { gracefully : parsed . gracefully } ) ;
109+ return { content : [ { type : 'text' , text : JSON . stringify ( v ) } ] } ;
110+ } catch ( error ) {
111+ if ( error instanceof ApifyApiError ) {
112+ log . error ( `[abortActorRun] Failed to abort run ${ parsed . runId } : ${ error . message } ` ) ;
113+ return { content : [ { type : 'text' , text : `Failed to abort run: ${ error . message } ` } ] } ;
114+ }
115+ throw error ;
116+ }
104117 } ,
105118 } as InternalTool ,
106119} ;
0 commit comments