"unhandledRejection" for Observables

20 views
Skip to first unread message

Alexander Mills

unread,
Dec 26, 2020, 11:26:22 PM12/26/20
to Angular and AngularJS discussion
In front-end JS, is there a way to catch errors globally?

For example, we might have:

const o = new Observable(o => {
    o.error('unhandled error')
});

o.subscribe(v => console.log('this never happens')


so we have a 1 sub, and so the observable becomes active, but there is nobody to catch the error, is there a way to capture the error globally?

Arnaud Deman

unread,
Dec 28, 2020, 7:19:34 AM12/28/20
to Angular and AngularJS discussion
Hi Alexander,

You could use an error callback in the subscription:
o.subscribe(
v => console.log('this never happens'),
err => console.log('this happens ;-)', err)
);

Regards,
Arnaud.


Reply all
Reply to author
Forward
0 new messages