Skip to content

Commit 0e1133f

Browse files
committed
fix error handling
1 parent 4357230 commit 0e1133f

File tree

1 file changed

+25
-4
lines changed
  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components

1 file changed

+25
-4
lines changed

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,36 @@ export function RowModal({ mode, isOpen, onClose, table, row, rowIds, onSuccess
174174
throw new Error(result.error || 'Failed to delete row')
175175
}
176176
} else {
177-
await Promise.all(
178-
idsToDelete.map((rowId) =>
179-
fetch(`/api/table/${table?.id}/rows/${rowId}`, {
177+
const results = await Promise.allSettled(
178+
idsToDelete.map(async (rowId) => {
179+
const res = await fetch(`/api/table/${table?.id}/rows/${rowId}`, {
180180
method: 'DELETE',
181181
headers: { 'Content-Type': 'application/json' },
182182
body: JSON.stringify({ workspaceId }),
183183
})
184-
)
184+
185+
if (!res.ok) {
186+
const result: { error?: string } = await res.json().catch(() => ({}))
187+
throw new Error(result.error || `Failed to delete row ${rowId}`)
188+
}
189+
190+
return rowId
191+
})
185192
)
193+
194+
const failures = results.filter((r) => r.status === 'rejected')
195+
196+
if (failures.length > 0) {
197+
const failureCount = failures.length
198+
const totalCount = idsToDelete.length
199+
const successCount = totalCount - failureCount
200+
const firstError =
201+
failures[0].status === 'rejected' ? failures[0].reason?.message || 'Unknown error' : ''
202+
203+
throw new Error(
204+
`Failed to delete ${failureCount} of ${totalCount} row(s)${successCount > 0 ? ` (${successCount} deleted successfully)` : ''}. ${firstError}`
205+
)
206+
}
186207
}
187208

188209
onSuccess()

0 commit comments

Comments
 (0)