Repository: ViacomInc/data-point (js)

Issue:
ReducerEntity should pass erro to input of catch
<!--
Thanks for your interest in the project. We appreciate bugs filed and PRs submitted!
Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Please fill/un-comment out this template with all the relevant information so we can
understand what's going on and fix the issue.
-->

**Problem description**:

```js

const error = new Error('test')
Model({
  value: () => {
    throw error
  },
  catch: (e) => {
    // error is not being passed
    e != error
  }
}
```

<!-- 
REPORTING BUG:

If you are reporting a bug, please provide the full error message/screenshots/anything.
-->

<!--If you have a link or example that reproduces your issue please include it. A reproduction with as little code as possible is better.-->

**Environment**:

- `data-point` version: canary

Pull request description:
fix entity not passing error
<!--
Thanks for your interest in the project. We appreciate bugs filed and PRs submitted!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!

BREAKING CHANGES:

If your PR includes a breaking change, please submit it with a codemod under
data-point-codemods that will help users upgrade their codebase.

Breaking changes without a codemod will not be accepted unless a codemod is not
viable or does not apply to the specific situation.
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->
**What**:

closes #423 

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Has Breaking changes
- [ ] Documentation
- [X] Tests
- [X] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [ ] Added username to **all-contributors** list

<!-- feel free to add additional comments -->

Patch:
diff --git a/packages/data-point/src/ReducerEntity.js b/packages/data-point/src/ReducerEntity.js
index 3d3b762..3b74f6e 100644
--- a/packages/data-point/src/ReducerEntity.js
+++ b/packages/data-point/src/ReducerEntity.js
@@ -75,22 +75,31 @@ class ReducerEntity extends Reducer {
   }
 
   async resolveReducer(accumulator, resolveReducer) {
-    let acc = accumulator;
+    let value;
+
     try {
-      acc.value = await this.resolveEntityValue(acc, resolveReducer);
+      value = await this.resolveEntityValue(accumulator, resolveReducer);
     } catch (error) {
       if (!this.catch) {
         throw error;
       }
 
-      acc = acc.set("value", await resolveReducer(acc, this.catch));
+      const catchValue = await resolveReducer(
+        accumulator.set("value", error),
+        this.catch
+      );
+
       if (this.outputType) {
-        await resolveReducer(acc, this.outputType);
+        await resolveReducer(
+          accumulator.set("value", catchValue),
+          this.outputType
+        );
       }
-      return acc.value;
+
+      return catchValue;
     }
 
-    return acc.value;
+    return value;
   }
 }
 


Test patch:
diff --git a/packages/data-point/src/ReducerEntity.test.js b/packages/data-point/src/ReducerEntity.test.js
index 8f22617..1b986ed 100644
--- a/packages/data-point/src/ReducerEntity.test.js
+++ b/packages/data-point/src/ReducerEntity.test.js
@@ -142,21 +142,25 @@ describe("ReducerEntity", () => {
       });
 
       it("should resolve this.catch", async () => {
+        const catchError = jest.fn(() => "catch");
+        const error = new Error("entityError");
+
         const entity = new ReducerEntity({
           name: "customEntity",
           value: () => "value",
-          catch: () => "catch"
+          catch: catchError
         });
 
         const mockResolveEntityValue = jest
           .spyOn(entity, "resolveEntityValue")
-          .mockRejectedValue(new Error("entityError"));
+          .mockRejectedValue(error);
 
         const acc = new Accumulator();
 
         const result = await entity.resolveReducer(acc, mockResolveReducer);
 
         expect(mockResolveEntityValue).toBeCalledWith(acc, mockResolveReducer);
+        expect(catchError).toHaveBeenCalledWith(error, { value: error });
         expect(mockResolveReducer).toHaveBeenCalledTimes(1);
         expect(result).toEqual("catch");
       });