Core interceptor pipeline execution engine.
Provides a lightweight interceptor chain pattern for handling cross-cutting concerns like logging, metrics, validation, and error handling in a declarative way.
Interceptors have three lifecycle functions:
The context map is threaded through all interceptors and contains:
Core interceptor pipeline execution engine. Provides a lightweight interceptor chain pattern for handling cross-cutting concerns like logging, metrics, validation, and error handling in a declarative way. Interceptors have three lifecycle functions: - :enter - executed in forward order during pipeline execution - :leave - executed in reverse order during successful completion - :error - executed in reverse order when an exception occurs The context map is threaded through all interceptors and contains: - :request - original request data - :op - operation identifier (keyword) - :system - dependency injection map - :correlation-id - request correlation ID - :halt? - flag to short-circuit pipeline execution - other keys added by interceptors during execution
(create-pipeline interceptors)Creates and validates a pipeline of interceptors.
Creates and validates a pipeline of interceptors.
(execute-interceptor-fn interceptor-fn ctx interceptor-name)Safely executes an interceptor function with error handling.
IMPORTANT: Preserve domain exceptions (ExceptionInfo with ex-data) so that their :type/:message/:violations are still visible to higher-level handlers. Only wrap non-ExceptionInfo throwables for additional interceptor context.
Safely executes an interceptor function with error handling. IMPORTANT: Preserve domain exceptions (ExceptionInfo with ex-data) so that their :type/:message/:violations are still visible to higher-level handlers. Only wrap non-ExceptionInfo throwables for additional interceptor context.
(get-from-context ctx key-path)(get-from-context ctx key-path default)Helper function to safely get values from context.
Helper function to safely get values from context.
(halt-pipeline ctx)(halt-pipeline ctx response-data)Helper function to halt pipeline execution with optional response data.
Helper function to halt pipeline execution with optional response data.
(run-enter-phase initial-ctx interceptors)Executes the :enter phase of interceptors in forward order. Returns [final-context executed-stack exception] where executed-stack contains interceptors that successfully executed their :enter function. If an exception occurs, it returns [partial-context partial-executed-stack exception].
Executes the :enter phase of interceptors in forward order. Returns [final-context executed-stack exception] where executed-stack contains interceptors that successfully executed their :enter function. If an exception occurs, it returns [partial-context partial-executed-stack exception].
(run-error-phase ctx executed-stack exception)Executes the :error phase of interceptors in reverse order when an exception occurs.
Executes the :error phase of interceptors in reverse order when an exception occurs.
(run-leave-phase ctx executed-stack)Executes the :leave phase of interceptors in reverse order.
Executes the :leave phase of interceptors in reverse order.
(run-pipeline initial-ctx interceptors)Executes a pipeline of interceptors with proper lifecycle management.
Args:
Returns:
Execution flow:
Short-circuiting:
Executes a pipeline of interceptors with proper lifecycle management. Args: - initial-ctx: Initial context map - interceptors: Vector of interceptor maps with :name, :enter, :leave, :error keys Returns: - Final context map after all interceptors have executed Execution flow: 1. Execute :enter functions in forward order until halt or completion 2. If successful, execute :leave functions in reverse order 3. If exception occurs, execute :error functions in reverse order Short-circuiting: - Any interceptor can set :halt? true in context to stop forward execution - :leave functions will still execute for already-executed interceptors
(update-context ctx key-path value)Helper function to safely update context with validation.
Helper function to safely update context with validation.
(validate-interceptor interceptor)Validates that an interceptor has the required structure.
Validates that an interceptor has the required structure.
(validate-pipeline interceptors)Validates a pipeline of interceptors.
Validates a pipeline of interceptors.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |