Interceptors
Interceptors wrap handlers for pre/post processing. Learn the Interceptable interface, the Aggregation pipeline operators, and how to transform responses.
Interceptors
Interceptors run after guards and wrap the handler. They receive an *aggregation.Aggregation which lets you transform, tap, time-out, or handle errors in the handler's response.
The Interceptable Interface
The Intercept method must call agg.Pipe(operators...) to invoke the handler and process its output.
Writing a Custom Interceptor
Aggregation Operators
Transform
Maps the handler response to a new value:
Tap
Runs a side-effect without changing the response:
Timeout
Enforces a deadline on the handler execution:
If the handler does not complete within the specified duration, the aggregation short-circuits and returns an error response.
Error
Handles errors that occur during handler execution:
Chaining Operators
Operators can be chained in a single Pipe call:
Interceptor Data
You can set data before calling Pipe that the handler can read via the aggregation: