Lỗi HTTP nên được xử lý ở đúng tầng: component/store xử lý lỗi nghiệp vụ cần hiển thị cụ thể; API service normalize response; interceptor xử lý cross-cutting concern như auth, retry, correlation id hoặc global error logging.
Ví dụ service trả fallback có kiểm soát:
typescript
loadUsers() {
return this.http.get<User[]>("/api/users").pipe(
retry({ count: 2, delay: 500 }),
catchError(error => {
this.logger.error(error)
return of([])
}),
)
}Không nuốt mọi lỗi ở interceptor vì component sẽ mất ngữ cảnh để hiển thị message đúng.