Skip to content

Commit 3790a4b

Browse files
committed
fix(ketch): add response.ok guards and fix registry ordering
1 parent ff63e36 commit 3790a4b

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

apps/sim/tools/ketch/get_consent.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ export const getConsentTool: ToolConfig<KetchGetConsentParams, KetchGetConsentRe
7070
},
7171

7272
transformResponse: async (response: Response) => {
73+
if (!response.ok) {
74+
let errorMessage = `Request failed with status ${response.status}`
75+
try {
76+
const data = await response.json()
77+
errorMessage = data.message ?? data.error ?? errorMessage
78+
} catch {
79+
// No JSON body in error response
80+
}
81+
return {
82+
success: false,
83+
output: {
84+
purposes: {},
85+
vendors: null,
86+
},
87+
}
88+
}
89+
7390
const data = await response.json()
7491
return {
7592
success: true,

apps/sim/tools/ketch/get_subscriptions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ export const getSubscriptionsTool: ToolConfig<
5858
},
5959

6060
transformResponse: async (response: Response) => {
61+
if (!response.ok) {
62+
let errorMessage = `Request failed with status ${response.status}`
63+
try {
64+
const data = await response.json()
65+
errorMessage = data.message ?? data.error ?? errorMessage
66+
} catch {
67+
// No JSON body in error response
68+
}
69+
return {
70+
success: false,
71+
output: {
72+
topics: {},
73+
controls: {},
74+
},
75+
}
76+
}
77+
6178
const data = await response.json()
6279
return {
6380
success: true,

apps/sim/tools/ketch/set_consent.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ export const setConsentTool: ToolConfig<KetchSetConsentParams, KetchSetConsentRe
7878
},
7979

8080
transformResponse: async (response: Response) => {
81+
if (!response.ok) {
82+
let errorMessage = `Request failed with status ${response.status}`
83+
try {
84+
const data = await response.json()
85+
errorMessage = data.message ?? data.error ?? errorMessage
86+
} catch {
87+
// No JSON body in error response
88+
}
89+
return {
90+
success: false,
91+
output: {
92+
purposes: {},
93+
},
94+
}
95+
}
96+
8197
if (response.status === 204) {
8298
return {
8399
success: true,

apps/sim/tools/ketch/set_subscriptions.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ export const setSubscriptionsTool: ToolConfig<
7777
},
7878

7979
transformResponse: async (response: Response) => {
80-
if (response.status === 204) {
80+
if (!response.ok) {
81+
let errorMessage = `Request failed with status ${response.status}`
82+
try {
83+
const data = await response.json()
84+
errorMessage = data.message ?? data.error ?? errorMessage
85+
} catch {
86+
// No JSON body in error response
87+
}
8188
return {
82-
success: true,
89+
success: false,
8390
output: {
84-
success: true,
91+
success: false,
8592
},
8693
}
8794
}
8895

89-
try {
90-
await response.json()
91-
} catch {
92-
// 204-like response with no body
93-
}
94-
9596
return {
9697
success: true,
9798
output: {

apps/sim/tools/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,12 +2685,12 @@ export const tools: Record<string, ToolConfig> = {
26852685
hex_run_project: hexRunProjectTool,
26862686
hex_update_project: hexUpdateProjectTool,
26872687
jina_read_url: jinaReadUrlTool,
2688+
jina_search: jinaSearchTool,
26882689
ketch_get_consent: ketchGetConsentTool,
26892690
ketch_get_subscriptions: ketchGetSubscriptionsTool,
26902691
ketch_invoke_right: ketchInvokeRightTool,
26912692
ketch_set_consent: ketchSetConsentTool,
26922693
ketch_set_subscriptions: ketchSetSubscriptionsTool,
2693-
jina_search: jinaSearchTool,
26942694
linkup_search: linkupSearchTool,
26952695
loops_create_contact: loopsCreateContactTool,
26962696
loops_create_contact_property: loopsCreateContactPropertyTool,

0 commit comments

Comments
 (0)