0

I need to check if a webapi backend is online from my angular app. I'm doing this by polling an endpoint on the api every 10 seconds. It's quite normal for the webapi to be offline. But I don't want to see a red error in chrome console every 10 seconds. Is it possible to swallow the error? The error looks like this... OPTIONS http://localhost:5400/ net::ERR_CONNECTION_REFUSED

I've tried doing a catchError on the http.get(...) call. But that doesn't stop chrome displaying the error in the console.

getUsers(): Observable<User[]> {
   return this.http.get<User[]>(this.apiUrl)
     .pipe(
       catchError(this.handleError)
     );
 }

handleError(error) {
   return observable.empty();
}
FeeFiFoFum
  • 1,498
  • 1
  • 9
  • 15
  • Can't do much without seeing your actual code, but in any case, have a look at this post: https://stackoverflow.com/questions/46019771/catching-errors-in-angular-httpclient/46019852 – Michael Beeson Jul 26 '19 at 00:40
  • @MichaelBeeson updated to include code. The error handler fires correctly. I just don't want that error appearing in chrome. – FeeFiFoFum Jul 26 '19 at 06:00

0 Answers0