Path: redb-route/redb.Route/Processors/ContextErrorLayerProcessor.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Processors/ContextErrorLayerProcessor.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Processors;
///
/// The outermost layer of a route's error scope (): the context's error handling for a
/// failure no OnException took — as Apache Camel's context error handler, which works only when no
/// onException matched. An that takes a failure returns (with
/// Handled(false) the failure stays on the exchange), one that does not take it rethrows; so this layer sees
/// exactly the failures nobody took.
///
/// The lookup is that of : a local handler of the route, a global handler,
/// . A handler that marks the exchange handled (
/// — a dead letter channel) ends the failure; otherwise it goes on to the caller, as with Camel's DefaultErrorHandler,
/// and so it does when nothing matched.
///
///
internal sealed class ContextErrorLayerProcessor : IProcessor
{
private readonly IProcessor _inner;
private readonly RouteContext _context;
private readonly string _routeId;
internal ContextErrorLayerProcessor(IProcessor inner, RouteContext context, string routeId)
{
_inner = inner;
_context = context;
_routeId = routeId;
}
///
public async Task Process(IExchange exchange, CancellationToken ct = default)
{
try
{
await _inner.Process(exchange, ct).ConfigureAwait(false);
}
// A genuine cancellation is never handled; a downstream timeout is named a TimeoutException, as in OnException.
catch (Exception ex) when (!RouteCancellation.IsCancellation(ex, ct))
{
// The route id is the compiled one: an exchange that went through a direct: route carries that route's id.
var handled = await _context.HandleWithContextHandlers(exchange, RouteCancellation.Normalize(ex, ct), _routeId, ct)
.ConfigureAwait(false);
if (!handled || !exchange.ExceptionHandled)
throw;
}
}
}