From 5b1e46bcd360ffe39da5bd3d0fc831dda6dfd414 Mon Sep 17 00:00:00 2001 From: Daniel Huisman Date: Fri, 27 Oct 2017 13:26:05 +0200 Subject: [PATCH] Release v2.0.1, return the result instead of throwing an error --- package.json | 2 +- src/middleware.js | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e43e83c..b8e984b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redux-cached-api", "description": "Redux middleware for calling and caching a (REST) API", - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "author": "Vereniging Campus Kabel (https://vck.tv)", "contributors": [ diff --git a/src/middleware.js b/src/middleware.js index 88ec1db..ed519f6 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -95,14 +95,14 @@ export const createApiMiddleware = (...apis) => { } } catch (err) { // Dispatch failure action - dispatchAction({ + const result = dispatchAction({ types: types.failure, isError: true, error: err }); - // Throw the error for the resulting promise - throw err; + // Return the failure action for the resulting promise + return result; } } @@ -119,14 +119,14 @@ export const createApiMiddleware = (...apis) => { }); } catch (err) { // Dispatch failure action - dispatchAction({ + const result = dispatchAction({ type: types.failure, isError: true, error: err }); - // Throw the error for the resulting promise - throw err; + // Return the failure action for the resulting promise + return result; } // The server responded with a status code outside the 200-399 range (i.e. error) @@ -168,12 +168,7 @@ export const createApiMiddleware = (...apis) => { payloadError: responsePayloadError }); - if (isError) { - // Throw the error for the resulting promise - throw error; - } else { - // Return the result for the resulting promise - return result; - } + // Return the success/failure action for the resulting promise + return result; }; };