diff --git a/src/index.js b/src/index.js index 2ecf558..350d3e6 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,11 @@ function isPromise(val) { return val && typeof val.then === 'function'; } +function isFetchRequest(request) { + if (!global.fetch) return request; + return request.bodyUsed === undefined ? request : request.json(); +} + export default function promiseMiddleware({ dispatch }) { return next => action => { if (!isFSA(action)) { @@ -14,7 +19,7 @@ export default function promiseMiddleware({ dispatch }) { return isPromise(action.payload) ? action.payload.then( - result => dispatch({ ...action, payload: result }), + result => dispatch({ ...action, payload: isFetchRequest(result) }), error => { dispatch({ ...action, payload: error, error: true }); return Promise.reject(error);