HandlerInterceptor

@ApiStatus.Experimental
fun interface HandlerInterceptor

Wraps a single handler invocation attempt for Kotlin coroutine handlers. Implementations must call next() exactly once.

Errors visible to the interceptor

The interceptor sees all errors except protocol errors occurring during invocation processing, for example:

  • Request/Response serialization/deserialization failures.

  • If the user handler throws, next() rethrows that exception unchanged.

  • Errors from an innermost interceptor.

Transforming errors

Interceptors can catch an Exception from next() and rethrow a different one.

A common pattern is to convert known-unrecoverable exceptions (e.g. IllegalArgumentException from input validation) into TerminalException.

⚠ Never catch or remap AbortedExecutionException

AbortedExecutionException is an internal SDK control-flow signal used to abort the current execution attempt during journal replay and suspension. Remapping it will corrupt the state machine and produce non-deterministic behavior. If you catch it, rethrow it as it is.

Types

Link copied to clipboard
@ApiStatus.Experimental
data class Context(val request: HandlerRequest, val attemptHeaders: HeadersAccessor)

Per-invocation context exposed to a HandlerInterceptor.

Link copied to clipboard
@ApiStatus.Experimental
fun interface Factory

Factory for HandlerInterceptor.

Functions

Link copied to clipboard
abstract suspend fun aroundHandler(context: HandlerInterceptor.Context, next: suspend () -> Unit)