Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
What is a forkJoin alternative that allows parallel requests to complete if one of them fails

I want to run some requests in parallel using forkJoin and combine their results as shown below. However, when one of the requests fails, the rest of the subscriptions are automatically cancelled by the browser. What is a simple alternative to forkJoin that lets me run requests in parallel and if one subscription fails, the rest are allowed to complete?

const posts = this.http.get("https://myApi.com/posts?userId=1");
const albums = this.http.get("https://myApi.com/albums?userId=1");

forkJoin([posts, albums]).subscribe((result) => {
  this.print(result[0], result[1]);
});

print(res1, res2) {
  const message = res1.text + res2.text;
  console.log(message);
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can achieve that using forkJoin, however, you have to handle the errors for each sub Observable separately using catchError to prevent canceling the stream if any error occurred.

You can try something like the following:

// import { catchError } from 'rxjs/operators';
// import { forkJoin, of } from 'rxjs';

const posts = this.http
  .get('https://myApi.com/posts?userId=1')
  .pipe(catchError((err) => of(err)));
const albums = this.http
  .get('https://myApi.com/albums?userId=1')
  .pipe(catchError((err) => of(err)));

forkJoin([posts, albums]).subscribe((result) => {
  this.print(result[0], result[1]);
});
about 4 years ago · Juan Pablo Isaza Report

0

I would make a function like

forkJoinReplaceErrors<T,R>(
  observables: Observable<T>[],
  ifError: ObservableInput<R>
) {
  return forkJoin(
    observables.pipe(
      catchError(() => ifError)
    )
  );
}

and then use that instead of forkJoin. Then it's more reusable and can be unit tested.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!