angular-interceptors

Intercept Angular HttpClient requests and responses for authentication, logging, and error handling.

6|1|Updated Feb 18, 2026
One-click install
npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-interceptors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: angular-interceptors
Source: https://github.com/oguzhan18/angular-ecosystem-skills/tree/main/skills/angular-interceptors
Command: npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-interceptors

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Intercepts and modifies Angular HttpClient requests and responses to centralize concerns like authentication, header injection, response transformation, caching flags, logging, and unified error handling so individual services remain thin and consistent.

Core Features & Use Cases

  • Functional Interceptors: Use HttpInterceptorFn to implement auth token attachment, header normalization, or request transformation without class boilerplate.
  • Registration and Composition: Register ordered interceptors via provideHttpClient with withInterceptors to ensure predictable processing order for logging, auth, and error handling.
  • Per-request Flags: Use HttpContext and HttpContextToken to enable caching or special handling on a per-request basis.
  • Error Handling and Navigation: Catch HttpErrorResponse in interceptors to trigger centralized retry, logout, or route navigation workflows.
  • Use Case: Attach a Bearer token to outgoing API calls, log request/response timings, and route to login on 401 responses while preserving a cache bypass flag per request.

Quick Start

Implement a functional auth interceptor that injects the current user's Bearer token, handle 401 errors by navigating to /login, and register it with provideHttpClient using withInterceptors.

Frequently Asked Questions about angular-interceptors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add auth tokens to Angular HttpClient requests centrally?

Angular HttpClient requests receive auth tokens centrally by implementing functional HttpInterceptorFn to attach Bearer headers. Register ordered interceptors via provideHttpClient with withInterceptors so all outgoing API calls carry authentication without modifying individual services.

How do I handle 401 errors and redirect to login in Angular?

Handle 401 errors by catching HttpErrorResponse within interceptors using RxJS stream operators. Centralize error handling to trigger logout or route navigation workflows to /login directly from the HTTP interceptor pipeline without duplicating logic in individual services.

Can I enable caching for specific Angular HTTP requests only?

Enable caching for specific HTTP requests using HttpContext and HttpContextToken. Set per-request flags to apply special handling, allowing interceptors to conditionally execute caching logic only when the token is passed with the request.

Does Angular 21 support functional interceptors without class boilerplate?

Angular 21 supports functional interceptors via HttpInterceptorFn, enabling auth token attachment and header transformation without class boilerplate. Register them using provideHttpClient with withInterceptors for predictable processing order across logging and error handling.

What is the best way to log request and response timings in Angular HttpClient?

Log request and response timings using functional interceptors within the HttpClient pipeline. Intercept HttpEvents using RxJS stream operators to measure and log durations centrally, keeping individual services thin and consistent.

How do I ensure predictable processing order for multiple Angular HTTP interceptors?

Ensure predictable processing order by registering ordered functional interceptors via provideHttpClient with withInterceptors. Compose logging, auth, and error handling interceptors sequentially so each stage processes the HttpEvent stream exactly as arranged.