https://grokonez.com/frontend/angular/error-handler-angular-6-httpclient-catcherror-retry-with-springboot-restapis-example

Error Handler Angular 6 HttpClient – catchError + retry – with SpringBoot RestAPIs example

In the tutorial, we show how to handle error from Angular HttpClient with catchError & retry when request fails on the SpringBoot server, or in case of a poor network connection.

Related posts:

Technologies

  • Angular 6
  • RxJS 6
  • Bootstrap 4
  • Visual Studio Code – version 1.24.0
  • SpringBoot

Error Handling

Error Object

Simple Angular HttpClient to request as below:

@Injectable({
  providedIn: 'root'
})
export class CustomerService {
  private customersUrl = 'http://localhost:8080/api/customers';  // URL to web api

  constructor( 
    private http: HttpClient
  ) { }

  getCustomers (): Observable {
    return this.http.get(this.customersUrl);
  }
}

What happens if the request fails on the server, or if a poor network connection?

  • Server is die -> console’s logs:
angular-6-retry-error-spring-boot-restapi---unknown-error-console-logs
  • 404 error -> console’s logs:
angular-6-retry-error-spring-boot-restapi---404-error-console-logs
  • 500 error -> console’s logs:
angular-6-retry-error-spring-boot-restapi---500-error-console-logs

-> HttpClient will return an error object.
We can handle it from Component code with .subcribe:

More at:

https://grokonez.com/frontend/angular/error-handler-angular-6-httpclient-catcherror-retry-with-springboot-restapis-example

Error Handler Angular 6 HttpClient – catchError + retry – with SpringBoot RestAPIs example

#angular #springboot #restapi #error-handler

Error Handler Angular 6 HttpClient - catchError + retry - with SpringBoot RestAPIs example
1.45 GEEK