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

119
Views
How to implement error handling in Angular and RXJS

I would like to perform error handling in the use case method using the subscription. If an error is thrown in the adapter, the handling should be performed in the use case. Unfortunately, the catch does not work with the example below, only the error from the adapter is thrown.

  public checkInUsecase(): void {
    this.checkInAdapter().subscribe(
      (data) => {
        this.logger.debug('Work...');
      },
      (error) => {
        this.logger.error('Error.');
      },
      () => {
        this.logger.debug('Successful.');
      }
    );
  }

  public checkInAdapter(): Observable<boolean> {
    throw new Error('Check in error');
  }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Error is thrown inside an observable. In your example the function is not returning an observable.

public checkInUsecase(): void {
    this.checkInAdapter()
        .pipe(catchError(err) => {
            this.logger.error('Error.');
            throw EMPTY;
        })
        .subscribe((data) => {
            this.logger.debug('Work...');
        });
}

public checkInAdapter(): Observable < boolean > { // this method needs to return an observable
    return new Observable((subscriber) => {
        if (!isAllGood) {
            throw Error('error message'); // error is thrown inside the observable.
        }
    });
}
about 4 years ago · Juan Pablo Isaza Report

0

There's a special pipe in Angular that allows you to catch errors in an Observable and react accordingly.

public checkInUsecase(): void {
  this.checkInAdapter()
    .pipe(catchError(err) => {
        this.logger.error('Error.');
        throw EMPTY;
    })
    .subscribe((data) => {
        this.logger.debug('Work...');
    });
}

public checkInAdapter(): Observable<boolean> {
  throw new Error('Check in error');
}
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!