Skip to content

Commit 4ae3a06

Browse files
committed
fix(davinci-client): remove try/catch from update dispatch — errors are now state
1 parent e5a9a2f commit 4ae3a06

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

packages/davinci-client/src/lib/client.store.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,8 @@ export async function davinci<ActionType extends ActionTypes = ActionTypes>({
333333
}
334334

335335
return function (value: CollectorValueTypes, index?: number) {
336-
try {
337-
store.dispatch(nodeSlice.actions.update({ id, value, index }));
338-
return null;
339-
} catch (err) {
340-
const errorMessage = err instanceof Error ? err.message : String(err);
341-
return {
342-
type: 'internal_error',
343-
error: { message: errorMessage, type: 'internal_error' },
344-
};
345-
}
336+
store.dispatch(nodeSlice.actions.update({ id, value, index }));
337+
return null;
346338
};
347339
},
348340

packages/davinci-client/src/lib/node.reducer.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('The node collector reducer', () => {
350350
]);
351351
});
352352

353-
it('should throw with no collectors', () => {
353+
it('should add an UnknownCollector with error when no matching collector is found', () => {
354354
const action = {
355355
type: 'node/update',
356356
payload: {
@@ -378,7 +378,10 @@ describe('The node collector reducer', () => {
378378
},
379379
},
380380
];
381-
expect(() => nodeCollectorReducer(state, action)).toThrowError('No collector found to update');
381+
const result = nodeCollectorReducer(state, action);
382+
const errorCollector = result.find((c) => c.id === 'submit-1');
383+
expect(errorCollector?.error).toBe('No collector found to update');
384+
expect(errorCollector?.category).toBe('UnknownCollector');
382385
});
383386

384387
it('should set error on ActionCollector when update is attempted', () => {

0 commit comments

Comments
 (0)