Skip to content

Commit ec31691

Browse files
fix(cloudflare): surface connections lookup failures and preserve cancellation
1 parent 5a93ac4 commit ec31691

1 file changed

Lines changed: 35 additions & 21 deletions

File tree

‎apps/sim/tools/cloudflare/get_tunnel.ts‎

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)