Skip to content

Commit 4325dc1

Browse files
push error handling
1 parent a4f8705 commit 4325dc1

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

packages/sources/node/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Elb, SourceNode } from './types';
2-
import { handleCommand, handleEvent } from './lib/handle';
32
import { run } from './lib/run';
43
import { getState } from './lib/state';
54
import { createPush } from './lib/push';
@@ -26,7 +25,7 @@ export function sourceNode(
2625
};
2726

2827
// Overwrite the push function with the instance-reference
29-
instance.push = createPush(instance, handleCommand, handleEvent);
28+
instance.push = createPush(instance);
3029

3130
// That's when the party starts
3231
run(instance);

packages/sources/node/src/lib/push.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ import {
1010
} from '@elbwalker/utils';
1111
import { isCommand } from './helper';
1212
import { destinationInit, destinationPush } from './destination';
13+
import { handleCommand, handleEvent } from './handle';
1314

14-
export function createPush(
15-
instance: SourceNode.Instance,
16-
handleCommand: SourceNode.HandleCommand,
17-
handleEvent: SourceNode.HandleEvent,
18-
): Elb.Fn {
15+
export function createPush(instance: SourceNode.Instance): Elb.Fn {
1916
const push = async (
2017
nameOrEvent: unknown,
2118
data: Elb.PushData = {},

packages/sources/walkerjs/src/lib/push.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,37 @@ export function createPush(instance: SourceWalkerjs.Instance): Elb.Fn {
2828
nested: WalkerOS.Entities = [],
2929
custom: WalkerOS.Properties = {},
3030
) => {
31-
const { event, command } = createEventOrCommand(
32-
instance,
33-
nameOrEvent,
34-
pushData,
35-
pushContext,
36-
nested,
37-
custom,
38-
options,
39-
);
40-
41-
if (command) {
42-
// Command event
43-
handleCommand(instance, command, pushData, options);
44-
} else if (event) {
45-
// Regular event
46-
handleEvent(instance, event);
47-
}
31+
return tryCatch(
32+
(
33+
nameOrEvent: unknown,
34+
pushData: Elb.PushData,
35+
options: Elb.PushOptions,
36+
pushContext: Elb.PushContext,
37+
nested: WalkerOS.Entities,
38+
custom: WalkerOS.Properties,
39+
) => {
40+
const { event, command } = createEventOrCommand(
41+
instance,
42+
nameOrEvent,
43+
pushData,
44+
pushContext,
45+
nested,
46+
custom,
47+
options,
48+
);
49+
50+
if (command) {
51+
// Command event
52+
handleCommand(instance, command, pushData, options);
53+
} else if (event) {
54+
// Regular event
55+
handleEvent(instance, event);
56+
}
57+
},
58+
() => {
59+
// @TODO custom error handling
60+
},
61+
)(nameOrEvent, pushData, options, pushContext, nested, custom);
4862
};
4963

5064
return useHooks(push, 'Push', instance.hooks);

0 commit comments

Comments
 (0)