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:
- 404 error -> console's logs:
- 500 error -> console's logs:
-> HttpClient
will return an error
object.
We can handle it from Component
code with .subcribe
:
More at:
Error Handler Angular 6 HttpClient – catchError + retry – with SpringBoot RestAPIs example
Top comments (0)