diff --git a/packages/jsonrpc/src/redux.test.ts b/packages/jsonrpc/src/redux.test.ts index 33d66bf..1938208 100644 --- a/packages/jsonrpc/src/redux.test.ts +++ b/packages/jsonrpc/src/redux.test.ts @@ -225,6 +225,7 @@ describe('createActions', () => { error = err } expect(error!).toBeTruthy() + expect(store.getState().mapping.error).toMatch(/status code 500/) expect(store.getState().handler.error).toMatch(/status code 500/) }) }) diff --git a/packages/redux/src/middleware/PromiseMiddleware.ts b/packages/redux/src/middleware/PromiseMiddleware.ts index e14dc98..d8c5d9f 100644 --- a/packages/redux/src/middleware/PromiseMiddleware.ts +++ b/packages/redux/src/middleware/PromiseMiddleware.ts @@ -24,21 +24,26 @@ export class PromiseMiddleware { if (!isPromise(payload)) { return next(action) } - const pendingAction = { - ...action, - status: 'pending', - } - // Propagate this action. Only attach listeners to the promise. - next(pendingAction) - payload + const promise = payload .then(result => { store.dispatch({ ...action, payload: result, status: 'resolved', }) + return result }) + + const pendingAction = { + ...action, + payload: promise, + status: 'pending', + } + // Propagate this action. Only attach listeners to the promise. + next(pendingAction) + + promise .catch(err => { store.dispatch({ ...action,