Interceptors
Type definitions for request and response interceptors.
These types are used when configuring interceptors in TMDBOptions.
RequestInterceptorContext
The context object passed to every RequestInterceptor before a request is made.
Prop
Type
RequestInterceptor
A function that runs before each TMDB API request.
type RequestInterceptor = (
context: RequestInterceptorContext,
) => RequestInterceptorContext | void | Promise<RequestInterceptorContext | void>;- Return
void(orundefined) to leave the request unchanged. - Return a new
RequestInterceptorContextto overrideendpointand/orparams. - Async interceptors are fully supported — the client awaits each one in order.
See the Interceptors guide for usage examples.
ResponseSuccessInterceptor
Called after every successful response, before the data is returned to the caller. Designed for side effects only — logging, caching, monitoring.
type ResponseSuccessInterceptor = (data: unknown) => void | Promise<void>;- Receives the parsed, null-sanitised response as
unknown. - Return
void— the original data is always forwarded to the caller unchanged. - This hook is not intended for data transformation or field augmentation.
- Async interceptors are supported.
- Does not run when the response is an error.
ResponseErrorInterceptor
Called after an error response has been normalised into a TMDBError.
type ResponseErrorInterceptor = (error: TMDBError) => void | Promise<void>;- Receives a fully typed
TMDBError— never rawunknown. - Return type is always
void— this hook is for side effects only. - The
TMDBErroris always re-thrown after the interceptor runs; it cannot be suppressed. - Does not run on successful responses.
See the Interceptors guide for usage examples.