1.3 KiB
1.3 KiB
ADR 0004: HTTP Interceptors Pipeline
Date: 2026-04-26 Status: Accepted
Context
Every API call requires the same three cross-cutting concerns:
- Prepend the API base URL so services don't hard-code it.
- Attach the JWT bearer token when one exists.
- Unwrap error responses into a consistent shape.
Handling these ad hoc in each service would duplicate logic and couple services to environment details.
Decision
Three functional interceptors are chained in order in app.config.ts:
apiInterceptor— prependsenvironment.apiBaseUrlto every outgoing request URL. Consequence: all services call relative paths (e.g./skydive/jumps), never absolute URLs.tokenInterceptor— attachesAuthorization: Token <jwt>when a token exists inJwtService.errorInterceptor— unwrapserr.errorfrom HttpErrorResponse and rethrows, so subscribers receive the API error payload directly.
Consequences
- Positive: Services are environment-agnostic. Swapping the API base URL requires changing only
environment.ts. - Positive: Auth header injection is transparent to all services.
- Positive: Error handling is uniform across the application.
- Constraint: Services must always use relative paths starting with
/. Absolute URLs would get the base URL prepended, breaking them.