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.

Chaining Http requests catch only on first one

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/common/http

Is this a regression?

No

Description

I’m chaining Angular Http request as following. The issue is when the first request fails, I get it on error callback, but if the second one fails, nothing happens.

this.myService.requestOne(this.data)
.pipe(mergeMap(dataOne=>{
  return this.myService.requestTwo(dataOne);
}))
.subscribe(dataTwo=>{
  this.loading = false;
},
(err)=>{
  // this fires when only requestOne get failed
  this.loading = false;
});

🌍 Your Environment

Angular Version:



@angular-devkit/architect       0.1001.4
@angular-devkit/build-angular   0.1001.4
@angular-devkit/core            10.1.4
@angular-devkit/schematics      10.1.6
@angular/animations             10.1.5
@angular/cdk                    10.2.4
@angular/material               10.2.4
@schematics/angular             10.1.6
@schematics/update              0.1001.4 (cli-only)
rxjs                            6.6.3
typescript                      4.0.3


Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewKushnircommented, Nov 4, 2020

Hi, I’m closing this ticket based on the comments above - it doesn’t seem to be an issue in the framework. Thank you.

1reaction
maroon1commented, Nov 4, 2020

@vahidvdn


this.myService
  .requestOne(this.data)
  .pipe(
-    mergeMap((dataOne) => {
+    switchMap((dataOne) => {
      return this.myService.requestTwo(dataOne);
    }),
  )
  .subscribe(
    (dataTwo) => {
      this.loading = false;
    },
    (err) => {
      // this fires when only requestOne get failed
      this.loading = false;
    },
  );
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular chaining Http requests catch only on first one
I'm chaining Angular Http request as following. The issue is when the first request fails, I get it on error callback, but if...
Read more >
Angular chaining Http requests catch only on first one-rx.js
Coding example for the question Angular chaining Http requests catch only on first one-rx.js.
Read more >
Chain HTTP Requests in React Using Promises - Pluralsight
By chaining Promises together, you can not only guarantee that one Promise will complete directly after the others prior to it are completed,Β ......
Read more >
Promises chaining - The Modern JavaScript Tutorial
A Promise keeps an internal state. It calls the handler wrapped in a try...catch block and stores the error. That is why asynchronous...
Read more >
Chaining 3 dependent HTTP request subscriptions one, which ...
As you can see, there are 3 levels of API calls (regular HTTP GET requests with JSON responses) that chain together. The first...
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