How to deal with Observable 'Cannot read property 'ngOriginalError' of undefined'
I got this error, when I threw a null
accidentally. Like this:
throw null;
It had nothing to do with any subscriptions or observables, at least not explicitly.
Related videos on Youtube
![Nitin](https://lh4.googleusercontent.com/-g0T-ATmcb3k/AAAAAAAAAAI/AAAAAAAAAAA/APUIFaMHSFh_WNZyziahKB8zlSY6igoy0g/mo/photo.jpg?sz=256)
Nitin
Updated on June 04, 2022Comments
-
Nitin about 2 years
I have created a service which handles HTTP calls and returns the response to the caller only if the result is successful.
I'm using Angular observable Map operator to check the result and status code and if the response does not have desired output then it should stop the observer pipeline after throwing a custom error message, which is being caught in catchError block which is working but at the same time getting uncaught Error in the console.
Angular version - 5+, Rxjs version- 5+
fetchRecords(): Observable < any > { return this.httpService.getData('cmpgnInfo/outlets').pipe( map((response: any) => { if (response[0].status !== 'ERROR') { throw new Error('Not able to details.'); } return response[0].results; }), catchError(err => Observable.throw(this.showError('Outlets', err))) ); } showError(logString: string, message ? : string) { this.logService.error(`Failed to load ${logString}`); this.modalService.showErrMessage(message); }
how to deal with this Subscriber uncaught error? what is wrong with the code which is causing this.
Subscriber.js:247 Uncaught TypeError: Cannot read property 'ngOriginalError' of undefined at getOriginalError (core.js:1430) at ErrorHandler._findOriginalError (core.js:1548) at ErrorHandler.handleError (core.js:1505) at Object.next (core.js:5508) at SafeSubscriber.schedulerFn [as _next] (core.js:4342) at SafeSubscriber.__tryOrUnsub (Subscriber.js:243) at SafeSubscriber.next (Subscriber.js:190) at Subscriber._next (Subscriber.js:131) at Subscriber.next (Subscriber.js:95) at EventEmitter.Subject.next (Subject.js:56) at EventEmitter.emit (core.js:4322) at eval (core.js:4782) at ZoneDelegate.invoke (zone.js:334) at Zone.run (zone.js:126) at NgZone.runOutsideAngular (core.js:4708)
-
CruelEngine over 5 years
this.showError()
is always undefined as its scope has changed . And alsoObservable.throw()
throws error but you are calling a function instead . Change it tocatchError(err =>this.showError('Outlets',err))
and thenreturn Observable.throw()
insideshowError()
-
Nitin over 5 yearsI saw one of the posts which have this suggested ans and I followed the same and ended up with this error stackoverflow.com/questions/46018259/…
-
CruelEngine over 5 yearsTry the solution i've suggested and let me know if it works
-
SiddAjmera over 5 yearsCan you replicate this on a Sample StackBlitz?
-
Nitin over 5 yearsits not working. catchError(err => { this.showError('Outlets', err); return Observable.throw(); })
-
Nitin over 5 years@SiddAjmera let me try
-
CruelEngine over 5 years@Nitin , are you facing the same error ?
-
Nitin over 5 yearssome syntax error it has. let me know if below code is correct first. catchError((err:any) => { this.showError('Outlets',err); Observable.throw(); //tried adding return statment as well but still error }
-
CruelEngine over 5 years@Nitin can you remove
this.showError()
and tryreturn Observable.throw(err)
? let me know if error persists -
Nitin over 5 yearssince I'm not handling this error and simply using this observable.throw(err); console displays the error passed from map operator R ZoneAwareError {__zone_symbol__error: Error: Not able to load Outlets. Contact IRI support. at MapSubscriber.eval [as project] (webpac…, …}
-
-
TRiNE over 3 yearssame here. it was a mistake to had
throw
instead ofreturn