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

206
Views
how to handle observable errors but continue with follow on observables?

I have an observable, does an http get in the middle of processing other observables. In the case of the http get response code of anything but 200, I want to take note of this error but proceed to the next observable.

So far I have this:

this.getConfigurationSettings()
    .do(config => {
        console.log('configuration settings.: ', config);
        this.configSettings = config;
        this.subscriptionService.setWSAddressProvider('badUrl');
    })
    .switchMap(config => this.askForWSData())
    .do(config =>
        console.log('askForWSData' + config))
    .switchMap(r => this.processWSData())
    .subscribe(
        config => {
            console.log('start of data processing: ' + config);
        },
        err => {
            // Log errors if any
            console.log(err);
        },
        () => console.log('app exiting'));

and the observable that can return an http error code is the following:

setWSAddressProvider() : Observable<string[]> {
    return this.http.get('badUrl')
        .map((res:Response) => {
            this.address = res.text();
            return [res.text()];
        });
        // .catch((error:any) =>
        // Observable.throw('Server error')
        // );
}

the above case generate a 400 response code. I want to log that return but go on to other observables. How to do that?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use catch to handle http errors

setWSAddressProvider() : Observable<string[]> {
    return this.http.get('badUrl')
        .map((res:Response) => {
            this.address = res.text();
            return [res.text()];
        });
       .catch((error: Response | any) => {
           if (error instanceof Response) {
                if (error.status === 400) {
                    console.log("Server responded with 400");
                    // Create a new observable with the data for the rest of the chain
                    return Observable.of([]);
                }
           }
           // Re-throw unhandled error
           return Observable.throw(err);
    });

}

over 4 years ago · Santiago Trujillo Report

0

Try using the Observable onErrorResumeNext function:

setWSAddressProvider() : Observable<string[]> {
    return this.http.get('badUrl')        
        .map((res:Response) => {
            this.address = res.text();
            return [res.text()];
        })
       .onErrorResumeNext((error: Response | any) => {
           if (error instanceof Response) {
                if (error.status === 400) {
                    console.log("Server responded with 400");
                }
                return [];
           }
    });
  }

See https://xgrommx.github.io/rx-book/content/getting_started_with_rxjs/creating_and_querying_observable_sequences/error_handling.html#ignoring-errors-with-onerrorresumenext

and this answer: Difference between catch and onErrorResumeNext

over 4 years ago · Santiago Trujillo 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!