Class FlattenValidationErrorsExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Extension methods for extracting ValidationError data from failed results.
public static class FlattenValidationErrorsExtensions
- Inheritance
-
FlattenValidationErrorsExtensions
- Inherited Members
Methods
FlattenValidationErrors<T>(Result<T>)
Extracts and merges all ValidationError field errors from the result's error. If the error is an AggregateError, all nested validation errors are flattened and merged. If the error is a ValidationError, it is returned directly.
public static ValidationError? FlattenValidationErrors<T>(this Result<T> result)
Parameters
resultResult<T>The result to extract validation errors from.
Returns
- ValidationError
A merged ValidationError containing all field errors, or null if no validation errors exist.
Type Parameters
TType of the result value.
Remarks
Warning: Non-validation errors within an AggregateError are silently discarded. If the aggregate contains a mix of ValidationError and other error types (e.g., DomainError), only the validation errors are returned.
For full control over all error types in an aggregate, use the onAggregate parameter
on MatchError<TIn, TOut>(Result<TIn>, Func<TIn, TOut>, Func<ValidationError, TOut>?, Func<NotFoundError, TOut>?, Func<ConflictError, TOut>?, Func<BadRequestError, TOut>?, Func<UnauthorizedError, TOut>?, Func<ForbiddenError, TOut>?, Func<DomainError, TOut>?, Func<RateLimitError, TOut>?, Func<ServiceUnavailableError, TOut>?, Func<UnexpectedError, TOut>?, Func<AggregateError, TOut>?, Func<Error, TOut>?) instead.