Kind: Class
Source: Frontend/src/app/InterceptorTokenRefresh.ts (line 13)
Part of: Frontend
TokenRefreshInterceptor handles token refresh behavior within the Angular HTTP request pipeline. Its intercept() method receives HTTP events, coordinates refresh handling when authentication state requires it, and returns an Observable<HttpEvent<any>> to continue the request flow.
Implements: HttpInterceptor
Methods
| Method | Signature | Returns |
|---|---|---|
intercept | intercept(request: HttpRequest<any>, next: HttpHandler) | Observable<HttpEvent<any>> |
Properties
| Property | Type |
|---|---|
countRequest | number |
Where it refuses work
TokenRefreshInterceptorstops the work with an early return whenevent.body instanceof Blob || event.body instanceof ArrayBuffer, in 3 places.TokenRefreshInterceptorstops the work with an early return when!this.networkService.isOnline().TokenRefreshInterceptorstops the work with an early return whenerror.status === 401 && !this.isRefreshTokenRequest(request).TokenRefreshInterceptorstops the work with an early return whenbody === null || body === undefined.TokenRefreshInterceptorstops the work with an early return whenArray.isArray(body).TokenRefreshInterceptorstops the work with an early return whentypeof body === 'string' && this.isoDateRegex.test(body).
Diagram
mermaidgraph LR A[Application Request] --> B[HttpClient] B --> C[TokenRefreshInterceptor] C --> D{Token requires refresh?} D -->|No| E[Send Request] D -->|Yes| F[Refresh Token] F --> E E --> G[HTTP Response] G --> C C --> H[Application]
Usage
tsimport { HTTP_INTERCEPTORS } from '@angular/common/http';
import { TokenRefreshInterceptor } from './InterceptorTokenRefresh';
@NgModule({
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: TokenRefreshInterceptor,
multi: true,
},
],
})
export class AppModule {}
AI Coding Instructions
- Keep
intercept()compatible with the AngularHttpInterceptorcontract and return anObservable<HttpEvent<any>>. - Do not subscribe inside the interceptor; compose refresh and request handling with RxJS operators.
- Register this class through the
HTTP_INTERCEPTORSprovider withmulti: true. - Prevent token refresh requests from being intercepted again, or they may trigger a refresh loop.
- Preserve HTTP errors when refresh handling fails so calling code can handle authentication failures.
Relationships
- IMPORTS →
AuthService - IMPORTS →
SppinerService - IMPORTS →
AppSettings - IMPORTS →
NetworkService
Used by
1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (1)
TranslateHandler—Frontend/src/app/app.module.ts:1
Was this page helpful?