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
responseobjectObject returned by the handler.
reasonstringCode or description of the failure when detected.
capturedFailureobjectCaptured error instance for further inspection.
Returns
- bool
truewhen a functional failure was identified; otherwisefalse.
TryGetErrorCode(object?)
Gets a standardized error code from the captured object.
string? TryGetErrorCode(object? capturedFailure)
Parameters
capturedFailureobjectInstance previously returned by TryExtractFailure(object?, out string, out object?).
Returns
- string
The interpreted code or
nullwhen not applicable.
TryGetErrorMessage(object?)
Gets a human-friendly message or detail from the captured error.
string? TryGetErrorMessage(object? capturedFailure)
Parameters
capturedFailureobjectInstance returned by TryExtractFailure(object?, out string, out object?).
Returns
- string
Message to display or
nullwhen unavailable.