diff --git a/src/store/promise-middleware.ts b/src/store/promise-middleware.ts index 4f9bf7d..3ca47b5 100644 --- a/src/store/promise-middleware.ts +++ b/src/store/promise-middleware.ts @@ -1,6 +1,6 @@ // Based on: https://github.com/acdlite/redux-promise/blob/master/src/index.js -function isPromise(val: any) { +function isPromise(val: any): val is Promise { return val && typeof val.then === 'function'; } @@ -9,10 +9,12 @@ export default function promiseMiddleware({ dispatch }: any) { if (isPromise(action.payload)) { dispatch({ ...action, payload: undefined }); - return action.payload.then( - (result: any) => dispatch({ ...action, payload: result }), - (error: Error) => dispatch({ ...action, payload: error, error: true }) - ); + return action.payload + .then((result: any) => dispatch({ ...action, payload: result })) + .catch((error: Error) => { + dispatch({ ...action, payload: error, error: true }); + return Promise.reject(error); + }); } else { return next(action); }