Question: I want to aggregate ( effectively de-duping ) and sum nested data the simplest way possible , through map / reduce / lodash or whatever. Can use ES6 / ES7 it doesn't matter. Simplest , cleanest is preferred . thanks.

I have an array e.g.

```
[{
    "orderNumber": "0001",
    "itemList": [{
            "item_code": "X1000",
            "qty": 10,
            "unit_price": 20
        },
        {
            "item_code": "X1002",
            "qty": 10,
            "unit_price": 20
        }
    ]
}, {
    "orderNumber": "0002",
    "itemList": [{
            "item_code": "X1000",
            "qty": 10,
            "unit_price": 20
        },
        {
            "item_code": "X1003",
            "qty": 10,
            "unit_price": 20
        }
    ]
}]

```

And I want to end up with;

```
[{
        "item_code": "X1000",
        "qty": 20,
        "unit_price": 20
    },
    {
        "item_code": "X1002",
        "qty": 10,
        "unit_price": 20
    },
    {
        "item_code": "X1003",
        "qty": 10,
        "unit_price": 20
    }
]

```

thanks for your time!

Answer: 
You are calling `.map` the wrong way in your `canActivate` method. If you see the documentation for `.map` (<http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-map>). You are using `map` a bit like the `subscribe` method. `map` can only transform every value yielded by the observable into another, so you shouldn't pass it the second parameter (the function that handles errors). In fact, if you pass `map` a second parameter it'll act as the `this` reference in the projection function (the first parameter).

The problem here is that, when you return an `ErrorObservable` you can't really apply `map` to it, you've got to subscribe to handle the error. See it in this example, where `error` is a `ErrorObservable` created via `Observable.throw`:

```js
let error = Rx.Observable.throw("error!"); // create an ErrorObservable

error.map(data => console.log(data)); // this has no effect, as the observable won't emit values.

error.subscribe({
   next: value => console.log("value", value), // as previously, won't execute
   error: error => console.log("error", error) // will execute
});

// You also can:

error.map(data => console.log('data', data)).subscribe({
  next: value => console.log('result', value),
  error: error => console.log('other way of handling it', error)
});
```

```html
<script src="https://unpkg.com/@reactivex/rxjs@5.5.0/dist/global/Rx.js"></script>
```

The `map` operator subscribes to the observable, but ignores errors (they pass through it).

However, you can chain both results, as demonstrated in my last example. This way you always catch an error and can act on it
```
this.getBase().subscribe(
      (next: BaseInfo) => {
          if(next === undefined){
            console.log('next ', 'hmm?');// because handleError2 return of(result as T);
          }else {
              console.log('next ', next);
          }
      },
      error =>{
          console.log('err ', error);// won't fire unless handleError2 throw error
      },
      () => {
          console.log('complete');
      }
  );

getBase() {
    return this.httpC.get<BaseInfo>(environment.apiServerUri + '/base1', this.extraHeader())
        .pipe(
            catchError(Utils.handleError2<BaseInfo>('getBase', undefined))
        );
}

public static handleError2<T>(operation = 'operation', result?: T) {
    return (error: HttpErrorResponse): Observable<T> => {
        console.error(error); // log to console instead
        ////throw(operation + ' failed'); // use this for subscribe(error:) to fire
        // Let the app keep running by returning an empty result.
        return of(result as T);
    };
}

```

After one and half month, I finally understand this issue.
It was my `handleError2` that catch the error but not throw.
Because my `handleError2` was not `'throw'` error back, the `'error'` function under the `getBase().subscribe()` won't fire.