Skip to content

Commit 4282ec1

Browse files
fix(overmind): fix managing errors with operators
1 parent be6059f commit 4282ec1

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

packages/node_modules/overmind-devtools/src/components/ActionOperator/index.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@ const ActionOperator: FunctionComponent<Props> = ({
5050
className={styles.operatorBody}
5151
onClick={(event) => event.stopPropagation()}
5252
>
53-
{operator.error ? (
54-
<div className={styles.operatorItem}>
55-
<span
56-
className={css(
57-
textStyles.description,
58-
textStyles.red,
59-
textStyles.monospace
60-
)}
61-
>
62-
error
63-
</span>
64-
<span
65-
className={css(textStyles.description, textStyles.monospace)}
66-
>
67-
{operator.error}
68-
</span>
69-
</div>
70-
) : null}
7153
{operator.events.map((event, index) => {
7254
if (event.type === EventType.Effect) {
7355
const effect = event.data as Effect
@@ -153,6 +135,24 @@ const ActionOperator: FunctionComponent<Props> = ({
153135
)
154136
}
155137
})}
138+
{operator.error ? (
139+
<div className={styles.operatorItem}>
140+
<span
141+
className={css(
142+
textStyles.description,
143+
textStyles.red,
144+
textStyles.monospace
145+
)}
146+
>
147+
error
148+
</span>
149+
<span
150+
className={css(textStyles.description, textStyles.monospace)}
151+
>
152+
{operator.error}
153+
</span>
154+
</div>
155+
) : null}
156156
</div>
157157
</div>
158158
</div>

packages/node_modules/overmind/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ export function pipe(...operators) {
987987
const run = (operatorErr, operatorContext) => {
988988
const operator = operators[operatorIndex++]
989989

990-
if (operatorContext.value instanceof Promise) {
990+
if (!operatorErr && operatorContext.value instanceof Promise) {
991991
context.execution.emit(EventType.OPERATOR_ASYNC, {
992992
...operatorContext.execution,
993993
isAsync: true,

packages/node_modules/overmind/src/operator.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ export function createOperator<ThisConfig extends IConfiguration>(
122122
): any {
123123
const operator = (err, context, next, final) => {
124124
startDebugOperator(type, name, context)
125-
try {
126-
let asyncTimeout = setTimeout(() => {
127-
context.execution.emit(EventType.OPERATOR_ASYNC, {
128-
...context.execution,
129-
isAsync: true,
130-
})
125+
let asyncTimeout = setTimeout(() => {
126+
context.execution.emit(EventType.OPERATOR_ASYNC, {
127+
...context.execution,
128+
isAsync: true,
131129
})
130+
})
131+
try {
132132
cb(
133133
err,
134134
{
@@ -152,21 +152,23 @@ export function createOperator<ThisConfig extends IConfiguration>(
152152
nextWithPath(...args)
153153
})
154154
} else {
155-
stopDebugOperator(context, value, {
156-
isSkipped: options.isSkipped,
155+
stopDebugOperator(context, err || value, {
156+
isSkipped: err ? true : options.isSkipped,
157157
})
158158
next(err, createContext(context, value))
159159
}
160160
},
161161
(err, value) => {
162162
clearTimeout(asyncTimeout)
163-
stopDebugOperator(context, value, {
164-
isIntercepted: true,
163+
stopDebugOperator(context, err || value, {
164+
isSkipped: Boolean(err),
165+
isIntercepted: !err,
165166
})
166167
final(err, createContext(context, value))
167168
}
168169
)
169170
} catch (error) {
171+
clearTimeout(asyncTimeout)
170172
stopDebugOperator(context, context.value, {
171173
error,
172174
})
@@ -208,13 +210,13 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
208210
})
209211
})
210212
}
211-
try {
212-
let asyncTimeout = setTimeout(() => {
213-
context.execution.emit(EventType.OPERATOR_ASYNC, {
214-
...context.execution,
215-
isAsync: true,
216-
})
213+
let asyncTimeout = setTimeout(() => {
214+
context.execution.emit(EventType.OPERATOR_ASYNC, {
215+
...context.execution,
216+
isAsync: true,
217217
})
218+
})
219+
try {
218220
cb(
219221
err,
220222
{
@@ -227,15 +229,16 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
227229
: context.execution.scopeValue(context.value, mutationTree),
228230
(err, value, options = {}) => {
229231
clearTimeout(asyncTimeout)
230-
stopDebugOperator(context, value, {
231-
isSkipped: options.isSkipped,
232+
stopDebugOperator(context, err || value, {
233+
isSkipped: err ? true : options.isSkipped,
232234
})
233235
next(err, createContext(context, value))
234236
},
235237
(err, value) => {
236238
clearTimeout(asyncTimeout)
237-
stopDebugOperator(context, value, {
238-
isIntercepted: true,
239+
stopDebugOperator(context, err || value, {
240+
isSkipped: Boolean(err),
241+
isIntercepted: !err,
239242
})
240243
final(err, createContext(context, value))
241244
}
@@ -264,6 +267,7 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
264267
})
265268
}
266269
} catch (error) {
270+
clearTimeout(asyncTimeout)
267271
stopDebugOperator(context, context.value, {
268272
error,
269273
})

0 commit comments

Comments
 (0)