Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Release v2.0.1, return the result instead of throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Oct 27, 2017
1 parent 1b392c0 commit 5b1e46b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <info@vck.tv> (https://vck.tv)",
"contributors": [
Expand Down
21 changes: 8 additions & 13 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
};
};

0 comments on commit 5b1e46b

Please sign in to comment.