Skip to content

Commit 8e68483

Browse files
committed
fix(ironclad): add JSON.parse error handling and .catch on error response
1 parent 13e8ea3 commit 8e68483

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

apps/sim/tools/ironclad/create_record.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ export const createRecordTool: ToolConfig<
6666
name: params.name,
6767
}
6868
if (params.properties) {
69-
body.properties = JSON.parse(params.properties)
69+
try {
70+
body.properties = JSON.parse(params.properties)
71+
} catch {
72+
throw new Error('Invalid JSON in properties field')
73+
}
7074
}
7175
if (params.links) {
72-
body.links = JSON.parse(params.links)
76+
try {
77+
body.links = JSON.parse(params.links)
78+
} catch {
79+
throw new Error('Invalid JSON in links field')
80+
}
7381
}
7482
return body
7583
},

apps/sim/tools/ironclad/create_workflow.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ export const createWorkflowTool: ToolConfig<
5252
template: params.template,
5353
}
5454
if (params.attributes) {
55-
body.attributes = JSON.parse(params.attributes)
55+
try {
56+
body.attributes = JSON.parse(params.attributes)
57+
} catch {
58+
throw new Error('Invalid JSON in attributes field')
59+
}
5660
}
5761
return body
5862
},

apps/sim/tools/ironclad/update_record.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ export const updateRecordTool: ToolConfig<
4747
'Content-Type': 'application/json',
4848
Accept: 'application/json',
4949
}),
50-
body: (params) => JSON.parse(params.properties),
50+
body: (params) => {
51+
try {
52+
return JSON.parse(params.properties)
53+
} catch {
54+
throw new Error('Invalid JSON in properties field')
55+
}
56+
},
5157
},
5258

5359
transformResponse: async (response: Response) => {

apps/sim/tools/ironclad/update_workflow_metadata.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ export const updateWorkflowMetadataTool: ToolConfig<
5050
'Content-Type': 'application/json',
5151
Accept: 'application/json',
5252
}),
53-
body: (params) => ({
54-
actions: JSON.parse(params.actions),
55-
}),
53+
body: (params) => {
54+
try {
55+
return { actions: JSON.parse(params.actions) }
56+
} catch {
57+
throw new Error('Invalid JSON in actions field')
58+
}
59+
},
5660
},
5761

5862
transformResponse: async (response: Response) => {
5963
if (!response.ok) {
60-
const data = await response.json()
61-
throw new Error(data.message || data.error || 'Failed to update workflow metadata')
64+
const data = await response.json().catch(() => ({}))
65+
throw new Error(
66+
(data as Record<string, string>).message ||
67+
(data as Record<string, string>).error ||
68+
'Failed to update workflow metadata'
69+
)
6270
}
6371

6472
return {

0 commit comments

Comments
 (0)