Friday, June 1, 2018

I have a friend who was experimenting with .pipe to catch errors at Observables in an Angular 5 application and that made me curious.

https://stackoverflow.com/questions/48030197/what-is-pipe-function-in-angular-2 touches on it and https://stackoverflow.com/questions/46197223/transforming-observable-with-map more generically touches on mapping. My friend was trying to do a .map inside of the pipe machinery. Some of her code was like:

.pipe(
   tap(d => this.log('foo')),
   catchError(this.handleError('bar', []))
);

 
 

I think the tap attempts to resolve the promise to test if it will resolve or if it will freak out and then the catchError stuff comes in. I should shut up. I don't really know what I am talking about. Maybe you can have a map inside like this:

.pipe(
   .map(x => x[0]),
   tap(d => this.log('foo')),
   catchError(this.handleError('bar', []))
);

 
 

I'm not sure what that does, getting the first thing inside of an Observable (is it its promise?) and then doing nothing with it. I thought the better thing to do might be:

.pipe(
   tap(d => this.log('foo')),
   catchError(this.handleError('bar', []))
).map(x => {
   return { betterThing: x.thing + 1 };
});

No comments:

Post a Comment