Table of Contents

Interface IFunctionalFailureDetector

Namespace
SimpleMediator
Assembly
SimpleMediator.dll

Allows the application to identify functional failures in mediator responses.

public interface IFunctionalFailureDetector

Examples

public sealed class PaymentOutcomeFailureDetector : IFunctionalFailureDetector
{
    public bool TryExtractFailure(object? response, out string reason, out object? capturedFailure)
    {
        if (response is PaymentOutcome outcome && outcome.TryGetError(out var paymentError))
        {
            reason = paymentError.Code ?? "payment.failure";
            capturedFailure = paymentError;
            return true;
        }

        reason = string.Empty;
        capturedFailure = null;
        return false;
    }

    public string? TryGetErrorCode(object? capturedFailure)
        => (capturedFailure as PaymentError)?.Code;

    public string? TryGetErrorMessage(object? capturedFailure)
        => (capturedFailure as PaymentError)?.Message;
}

Remarks

SimpleMediator relies on this abstraction to avoid binding to specific domain types. Implementations can inspect Either, discriminated unions, or custom objects to extract codes and messages.

Methods

TryExtractFailure(object?, out string, out object?)

Attempts to determine whether the response represents a functional failure.

bool TryExtractFailure(object? response, out string reason, out object? capturedFailure)

Parameters

response object

Object returned by the handler.

reason string

Code or description of the failure when detected.

capturedFailure object

Captured error instance for further inspection.

Returns

bool

true when a functional failure was identified; otherwise false.

TryGetErrorCode(object?)

Gets a standardized error code from the captured object.

string? TryGetErrorCode(object? capturedFailure)

Parameters

capturedFailure object

Instance previously returned by TryExtractFailure(object?, out string, out object?).

Returns

string

The interpreted code or null when not applicable.

TryGetErrorMessage(object?)

Gets a human-friendly message or detail from the captured error.

string? TryGetErrorMessage(object? capturedFailure)

Parameters

capturedFailure object

Instance returned by TryExtractFailure(object?, out string, out object?).

Returns

string

Message to display or null when unavailable.