Repository: ViacomInc/data-point (js)

Issue:
attach entityId to error
to help with debugging attach entityId to the error object

Line where to add code

https://github.com/ViacomInc/data-point/blob/master/lib/entity-types/resolve-entity/resolve-entity.js#L126

Pull request description:
feat(entity-types/*): attach entityId to error
closes #20

Patch:
diff --git a/lib/entity-types/resolve-entity/resolve-entity.js b/lib/entity-types/resolve-entity/resolve-entity.js
index ff940ff..95b621a 100644
--- a/lib/entity-types/resolve-entity/resolve-entity.js
+++ b/lib/entity-types/resolve-entity/resolve-entity.js
@@ -123,6 +123,8 @@ function resolveEntity (
       if (error.bypass === true) {
         return error.bypassValue
       }
+      // attach entity information to help debug
+      error.entityId = currentAccumulator.reducer.spec.id
 
       return resolveErrorReducers(error, currentAccumulator, resolveTransform)
     })


Test patch:
diff --git a/lib/entity-types/resolve-entity/resolve-entity.test.js b/lib/entity-types/resolve-entity/resolve-entity.test.js
index ef770bf..8328935 100644
--- a/lib/entity-types/resolve-entity/resolve-entity.test.js
+++ b/lib/entity-types/resolve-entity/resolve-entity.test.js
@@ -132,9 +132,9 @@ describe('ResolveEntity.resolveMiddleware', () => {
 const Resolve = require('../../resolve/reducer')
 
 describe('ResolveEntity.resolveEntity', () => {
-  const resolver = (acc, resolveTransform) => Promise.resolve(acc)
+  const defaultResolver = (acc, resolveTransform) => Promise.resolve(acc)
 
-  const resolveEntity = (entityId, input, options) => {
+  const resolveEntity = (entityId, input, options, resolver) => {
     const racc = helpers.createAccumulator.call(null, input, options)
     const reducer = ReducerEntity.create(entityId)
     return ResolveEntity.resolveEntity(
@@ -142,7 +142,7 @@ describe('ResolveEntity.resolveEntity', () => {
       resolveTransform,
       racc,
       reducer,
-      resolver
+      resolver || defaultResolver
     )
   }
 
@@ -152,6 +152,15 @@ describe('ResolveEntity.resolveEntity', () => {
     })
   })
 
+  test('It should attach entityId to error', () => {
+    const rejectResolver = () => Promise.reject(new Error('test'))
+    return resolveEntity('hash:asIs', undefined, undefined, rejectResolver)
+      .catch(error => error)
+      .then(val => {
+        expect(val).toHaveProperty('entityId', 'hash:asIs')
+      })
+  })
+
   test('It should log trace calls when set to true', () => {
     const consoleTime = console.time
     const consoleTimeEnd = console.timeEnd