Angular 7 (RxJs 6.x) - How to use throwError

Stéphane GRILLON

I want use second param (error) on my subcriber but dot not work.

Code of my Observable:

return Observable.create(obs => {
  cognitoidentityserviceprovider.adminCreateUser(params, function(error, data) {
    if (error) {
      console.log(error);
      return throwError(error || 'Server error');
    } else {
      console.log(data);
      return obs.next(data.User);
    }
  });
});

my console.log(error); is OK but after nothing (no trace).

Code of my subscriber:

this.myService.createUser(user).subscribe(
         result => this.getUsers(),
         error =>  this.errorUsersProcessor(error));

second param (error) on my subcriber never call.

Felix Movee

From the documentation : throwError

Creates an Observable that emits no items to the Observer and immediately emits > an error notification.

So my guess here is that the throwError is emiting an Error to a new observer not the one you are subscribing to.

You could try to notify you're actual observer to emit the error doing :

obs.error(error || new Error('Server error'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Could not use Observable.of in RxJs 6 and Angular 6

Angular : how to call finally() with RXJS 6

How to import rxjs timer in angular 6?

How do you sort an Observable<Item[]> in Angular 6 with rxjs 6?

How to use rxjs6 partition in typescript?

How to throwError within map of observable (rxjs6, ng6)

How to keep observable alive after error in RxJS 6 and Angular 6

How to use exceljs in angular 6

How to return value from subscribe of forkJoin with angular 6 and RxJs 6?

How to use race with rxjs 6

Angular HttpInterceptor: How to use RxJS for multiple conditions

How to use RxJs 6 with TypeScript and WebPack

Rxjs angular 6/7 mergeMap delay http request

How to fix " Property 'wheelDelta' does not exist on type 'WheelEvent' " while upgrading to angular 7,rxjs6?

How to use Rxjs switchMap to throwError

How to delay throwError with RxJS?

Angular 7 rxjs 6 bind to certain elements only

How to unit test a function is called correctly after a timer has fired. Angular 7, RXJS 6

Angular, NGRX how to use rxjs operator in ngOnInit

How to use subscribe-next RxJS in Angular?

How to use RxJS "throttle" operator in Angular 2

Angular 6 RxJs: Trying to make an obj as observable to be use in other components

RxJS throwError event not directed to handler?

Angular 7 RXjs 6.x - How to use forkJoin (difference between `of` and `Observable.create`)

Angular 7 (RxJs6) - Unit tests - How to check if service return throwError?

How to use combineLatest with flatMap in rxjs6?

how to use Rxjs filter in angular along with BehaviorSubject

Angular test throwError

RxJs7 deprecated throwError