30 lines
1.3 KiB
Markdown
30 lines
1.3 KiB
Markdown
# ADR 0004: HTTP Interceptors Pipeline
|
|
|
|
**Date:** 2026-04-26
|
|
**Status:** Accepted
|
|
|
|
## Context
|
|
|
|
Every API call requires the same three cross-cutting concerns:
|
|
|
|
1. Prepend the API base URL so services don't hard-code it.
|
|
2. Attach the JWT bearer token when one exists.
|
|
3. 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`:
|
|
|
|
1. **`apiInterceptor`** — prepends `environment.apiBaseUrl` to every outgoing request URL. Consequence: all services call relative paths (e.g. `/skydive/jumps`), never absolute URLs.
|
|
2. **`tokenInterceptor`** — attaches `Authorization: Token <jwt>` when a token exists in `JwtService`.
|
|
3. **`errorInterceptor`** — unwraps `err.error` from 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.
|