diff --git a/src/index.ts b/src/index.ts index 801d408..180971a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,7 +102,13 @@ function createStore< } }); await Promise.all(ps); - const result = await originalEffect(effectFn, payload, extra); + let result = null; + let error = null; + try { + result = await originalEffect(effectFn, payload, extra); + } catch (e) { + error = e; + } ps = []; produce(result, (res: any) => { for (const afterEffect of hookMap.afterEffect as Array< @@ -119,6 +125,9 @@ function createStore< } }); await Promise.all(ps); + if (error) { + throw error; + } return result; }; });