Skip to content

Commit 257a77e

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

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
@@ -336,16 +336,8 @@ export async function davinci<ActionType extends ActionTypes = ActionTypes>({
336336
}
337337

338338
return function (value: CollectorValueTypes, index?: number) {
339-
try {
340-
store.dispatch(nodeSlice.actions.update({ id, value, index }));
341-
return null;
342-
} catch (err) {
343-
const errorMessage = err instanceof Error ? err.message : String(err);
344-
return {
345-
type: 'internal_error',
346-
error: { message: errorMessage, type: 'internal_error' },
347-
};
348-
}
339+
store.dispatch(nodeSlice.actions.update({ id, value, index }));
340+
return null;
349341
};
350342
},
351343

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

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

355-
it('should throw with no collectors', () => {
355+
it('should add an UnknownCollector with error when no matching collector is found', () => {
356356
const action = {
357357
type: 'node/update',
358358
payload: {
@@ -380,7 +380,10 @@ describe('The node collector reducer', () => {
380380
},
381381
},
382382
];
383-
expect(() => nodeCollectorReducer(state, action)).toThrowError('No collector found to update');
383+
const result = nodeCollectorReducer(state, action);
384+
const errorCollector = result.find((c) => c.id === 'submit-1');
385+
expect(errorCollector?.error).toBe('No collector found to update');
386+
expect(errorCollector?.category).toBe('UnknownCollector');
384387
});
385388

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

0 commit comments

Comments
 (0)