File tree Expand file tree Collapse file tree
apps/sim/tools/cloudflare Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,24 +44,26 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
4444 ) => {
4545 const data = await response . json ( )
4646
47+ const emptyOutput = {
48+ id : '' ,
49+ name : null ,
50+ account_tag : null ,
51+ config_src : null ,
52+ status : null ,
53+ tun_type : null ,
54+ remote_config : null ,
55+ metadata : null ,
56+ created_at : null ,
57+ deleted_at : null ,
58+ conns_active_at : null ,
59+ conns_inactive_at : null ,
60+ connections : null ,
61+ }
62+
4763 if ( ! data . success ) {
4864 return {
4965 success : false ,
50- output : {
51- id : '' ,
52- name : null ,
53- account_tag : null ,
54- config_src : null ,
55- status : null ,
56- tun_type : null ,
57- remote_config : null ,
58- metadata : null ,
59- created_at : null ,
60- deleted_at : null ,
61- conns_active_at : null ,
62- conns_inactive_at : null ,
63- connections : null ,
64- } ,
66+ output : emptyOutput ,
6567 error : cloudflareErrorMessage ( data , 'Failed to get tunnel' ) ,
6668 }
6769 }
@@ -77,13 +79,25 @@ export const getTunnelTool: ToolConfig<CloudflareGetTunnelParams, CloudflareTunn
7779 signal : context ?. signal ,
7880 } )
7981 const connectionsData = await connectionsRes . json ( )
80- if ( connectionsData ?. success && Array . isArray ( connectionsData . result ) ) {
81- connections = connectionsData . result . flatMap (
82- ( connector : { conns ?: unknown [ ] } ) => connector . conns ?? [ ]
83- )
82+ if ( ! connectionsRes . ok || ! connectionsData ?. success ) {
83+ return {
84+ success : false ,
85+ output : emptyOutput ,
86+ error : cloudflareErrorMessage ( connectionsData , 'Failed to get tunnel connections' ) ,
87+ }
88+ }
89+ connections = Array . isArray ( connectionsData . result )
90+ ? connectionsData . result . flatMap (
91+ ( connector : { conns ?: unknown [ ] } ) => connector . conns ?? [ ]
92+ )
93+ : [ ]
94+ } catch ( error ) {
95+ if ( context ?. signal ?. aborted || ( error as Error ) ?. name === 'AbortError' ) throw error
96+ return {
97+ success : false ,
98+ output : emptyOutput ,
99+ error : 'Failed to get tunnel connections' ,
84100 }
85- } catch {
86- connections = null
87101 }
88102 }
89103
You can’t perform that action at this time.
0 commit comments