Path: redb-route/demo/SerialNumbersDemo/SerialNumbers.Core/Infrastructure/ExceptionRouteBuilder.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/demo/SerialNumbersDemo/SerialNumbers.Core/Infrastructure/ExceptionRouteBuilder.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Core;
using redb.Route.RedbCore.Extensions;
using SerialNumbers.Core.Services;
namespace SerialNumbers.Core.Infrastructure;
///
/// Exception handlers for the whole context: an OnException declared in any route builder
/// wraps every route of the module.
///
/// Only for a failure whose right outcome is "take the message and record it": a handled
/// exception is a success for the consumer, so the SFTP file moves to .done and an AS2
/// sender gets a positive MDN. A catch-all OnException<Exception>().Handled(true)
/// is right for an HTTP API, where it turns any error into an error response, and wrong for
/// file and message consumers, where it would acknowledge a message the database never saw.
/// Technical failures are left unhandled on purpose: the transaction rolls back and the file
/// stays with the partner for the next poll.
///
///
public sealed class ExceptionRouteBuilder : RouteBuilder
{
protected override void Configure()
{
OnException()
.Handled(true)
.ProcessWithRedb(IntakeRecorder.RecordParkedAsync)
.Log("${header.serials.partner}: ${header.serials.fileName} parked, " +
"no route for message type ${header.serials.messageType}", LogLevel.Warning)
// The steps the message went through before it was parked, with their timings. Collected by
// .MessageHistory() on the intake and request routes; without a step that prints it the trace
// stays inside the exchange.
.Log(MessageHistory.Format, LogLevel.Warning);
}
}