Performance: Handling HTTP errors
MEDIUM IMPACT
This affects the responsiveness and smoothness of user interactions by managing how HTTP errors impact UI updates and loading states.
this.http.get('/api/data').pipe(catchError(err => { this.errorMessage = 'Failed to load data'; return of([]); })).subscribe(data => { this.data = data; });
this.http.get('/api/data').subscribe(data => { this.data = data; }, error => { alert('Error occurred'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking alert on error | Minimal | 0 | Blocks UI thread causing delayed paint | [X] Bad |
| Non-blocking catchError with fallback | Minimal | 1 (UI update) | Efficient paint with minimal reflow | [OK] Good |
| Blind retry without delay | Minimal | 0 | Delays error feedback, increasing perceived latency | [!] OK |
| Retry with delay and limit | Minimal | 1 (UI update) | Balanced paint cost with timely feedback | [OK] Good |