Skip to content

Commit 367964f

Browse files
fix(overmind): fix general error handling issues
1 parent 624e7bc commit 367964f

File tree

1 file changed

+18
-20
lines changed
  • packages/node_modules/overmind/src

1 file changed

+18
-20
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ export class Overmind<ThisConfig extends IConfiguration>
586586
isPending: true,
587587
error: false,
588588
})
589-
result
589+
590+
return result
590591
.then((promisedResult) => {
591592
// eslint-disable-next-line standard/no-callback-literal
592593
this.eventHub.emit(EventType.EFFECT, {
@@ -597,6 +598,8 @@ export class Overmind<ThisConfig extends IConfiguration>
597598
isPending: false,
598599
error: false,
599600
})
601+
602+
return promisedResult
600603
})
601604
.catch((error) => {
602605
this.eventHub.emit(EventType.EFFECT, {
@@ -608,18 +611,18 @@ export class Overmind<ThisConfig extends IConfiguration>
608611
})
609612
throw error
610613
})
611-
} else {
612-
// eslint-disable-next-line standard/no-callback-literal
613-
this.eventHub.emit(EventType.EFFECT, {
614-
...execution,
615-
...effect,
616-
args: safeValues(effect.args),
617-
result: safeValue(result),
618-
isPending: false,
619-
error: false,
620-
})
621614
}
622615

616+
// eslint-disable-next-line standard/no-callback-literal
617+
this.eventHub.emit(EventType.EFFECT, {
618+
...execution,
619+
...effect,
620+
args: safeValues(effect.args),
621+
result: safeValue(result),
622+
isPending: false,
623+
error: false,
624+
})
625+
623626
return result
624627
})
625628
}
@@ -830,33 +833,28 @@ export function pipe(...operators) {
830833
const run = (operatorErr, operatorContext) => {
831834
const operator = operators[operatorIndex++]
832835

833-
if (!operator) return next(operatorErr, operatorContext)
834-
835-
if (operatorErr)
836-
return operator(operatorErr, operatorContext, run, final)
837-
838836
if (operatorContext.value instanceof Promise) {
839837
context.execution.emit(EventType.OPERATOR_ASYNC, {
840838
...operatorContext.execution,
841839
isAsync: true,
842840
})
843841
operatorContext.value
844842
.then((promiseValue) =>
845-
operator(
843+
(operator || next)(
846844
null,
847845
{ ...operatorContext, value: promiseValue },
848846
run,
849847
final
850848
)
851849
)
852850
.catch((promiseError) =>
853-
operator(promiseError, operatorContext, run, final)
851+
(operator || next)(promiseError, operatorContext, run, final)
854852
)
855853
} else {
856854
try {
857-
operator(null, operatorContext, run, final)
855+
;(operator || next)(operatorErr, operatorContext, run, final)
858856
} catch (operatorError) {
859-
operator(operatorError, operatorContext, run, final)
857+
;(operator || next)(operatorError, operatorContext, run, final)
860858
}
861859
}
862860
}

0 commit comments

Comments
 (0)