question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Observable and Http errors

See original GitHub issue

Can anybody explain me the mechanism of error handling? For example, I have 2 subscribers on one observer

  let observable = this.authService.signIn(formGroup.value.email, formGroup.value.password);
  
  // 1st subscriber
  observable.subscribe((response: SignInResponse) => {
    console.log('First - Success');
  }, () => {
    console.log('First - Error');
  }, () => {
    console.log('First - Finally');
  });
  
  // 2nd subscriber
  observable.subscribe((response: SignInResponse) => {
    console.log('Second - Success');
  }, () => {
    console.log('Second - Error');
  }, () => {
    console.log('Second - Finally');
  });`

If I get 400 from the server - both error messages First - Error, Second - Error appears as expected, but if I remove error and finally callback for the first subscriber as

  let observable = this.authService.signIn(formGroup.value.email, formGroup.value.password);
  
  observable.subscribe((response: SignInResponse) => {
    console.log('First - Success');
  });

  observable.subscribe((response: SignInResponse) => {
    console.log('Second - Success');
  }, () => {
    console.log('Second - Error');
  }, () => {
    console.log('Second - Finally');
  });

I don’t get the error callback of the second subscriber

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timaxapacommented, Mar 27, 2017

Yes, it will work. Thanks for your answer. Issue can be closed

0reactions
mackelitocommented, Mar 27, 2017

I´m using http instead of restangular here because of this issue, https://github.com/2muchcoffeecom/ng2-restangular/issues/14#issuecomment-272466188

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does HTTP error-handling work with observables?
Means: When you subscribe to a HTTP call, you always automatically get a success if you do not explicitly do Observable.throw ? Ok,...
Read more >
RxJs Error Handling: Complete Practical Guide
The Observable Contract and Error Handling. In order to understand error handling in RxJs, we need to first understand that any given stream...
Read more >
How to handle and catch errors in Rxjs
In short, we learn how to pipe the data and catch the errors using catchError , to modify the return observable or use...
Read more >
Angular HTTP Error Handling - TekTutorialsHub
In this guide, we learn about Angular HTTP Error Handling. Whenever the error occurs in an HTTP operation, the Angular wraps it in...
Read more >
Handling Exceptions Using the Angular HttpClient Service
Catching HTTP Exceptions ... Using the catchError operator gives you the ability to catch errors that may occur within an observable stream. Let's ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found