Class MatchErrorExtensionsAsync
- Namespace
- FunctionalDdd
- Assembly
- FunctionalDdd.RailwayOrientedProgramming.dll
Asynchronous pattern matching helpers for discriminating specific error types in Result.
public static class MatchErrorExtensionsAsync
- Inheritance
-
MatchErrorExtensionsAsync
- Inherited Members
Methods
MatchErrorAsync<TIn, TOut>(Result<TIn>, Func<TIn, CancellationToken, Task<TOut>>, Func<ValidationError, CancellationToken, Task<TOut>>?, Func<NotFoundError, CancellationToken, Task<TOut>>?, Func<ConflictError, CancellationToken, Task<TOut>>?, Func<BadRequestError, CancellationToken, Task<TOut>>?, Func<UnauthorizedError, CancellationToken, Task<TOut>>?, Func<ForbiddenError, CancellationToken, Task<TOut>>?, Func<DomainError, CancellationToken, Task<TOut>>?, Func<RateLimitError, CancellationToken, Task<TOut>>?, Func<ServiceUnavailableError, CancellationToken, Task<TOut>>?, Func<UnexpectedError, CancellationToken, Task<TOut>>?, Func<Error, CancellationToken, Task<TOut>>?, CancellationToken)
Asynchronously pattern matches on the result with async handlers for different error types.
public static Task<TOut> MatchErrorAsync<TIn, TOut>(this Result<TIn> result, Func<TIn, CancellationToken, Task<TOut>> onSuccess, Func<ValidationError, CancellationToken, Task<TOut>>? onValidation = null, Func<NotFoundError, CancellationToken, Task<TOut>>? onNotFound = null, Func<ConflictError, CancellationToken, Task<TOut>>? onConflict = null, Func<BadRequestError, CancellationToken, Task<TOut>>? onBadRequest = null, Func<UnauthorizedError, CancellationToken, Task<TOut>>? onUnauthorized = null, Func<ForbiddenError, CancellationToken, Task<TOut>>? onForbidden = null, Func<DomainError, CancellationToken, Task<TOut>>? onDomain = null, Func<RateLimitError, CancellationToken, Task<TOut>>? onRateLimit = null, Func<ServiceUnavailableError, CancellationToken, Task<TOut>>? onServiceUnavailable = null, Func<UnexpectedError, CancellationToken, Task<TOut>>? onUnexpected = null, Func<Error, CancellationToken, Task<TOut>>? onError = null, CancellationToken cancellationToken = default)
Parameters
resultResult<TIn>The result to match on.
onSuccessFunc<TIn, CancellationToken, Task<TOut>>Async function to execute on success.
onValidationFunc<ValidationError, CancellationToken, Task<TOut>>Async function to execute when the error is a ValidationError.
onNotFoundFunc<NotFoundError, CancellationToken, Task<TOut>>Async function to execute when the error is a NotFoundError.
onConflictFunc<ConflictError, CancellationToken, Task<TOut>>Async function to execute when the error is a ConflictError.
onBadRequestFunc<BadRequestError, CancellationToken, Task<TOut>>Async function to execute when the error is a BadRequestError.
onUnauthorizedFunc<UnauthorizedError, CancellationToken, Task<TOut>>Async function to execute when the error is an UnauthorizedError.
onForbiddenFunc<ForbiddenError, CancellationToken, Task<TOut>>Async function to execute when the error is a ForbiddenError.
onDomainFunc<DomainError, CancellationToken, Task<TOut>>Async function to execute when the error is a DomainError.
onRateLimitFunc<RateLimitError, CancellationToken, Task<TOut>>Async function to execute when the error is a RateLimitError.
onServiceUnavailableFunc<ServiceUnavailableError, CancellationToken, Task<TOut>>Async function to execute when the error is a ServiceUnavailableError.
onUnexpectedFunc<UnexpectedError, CancellationToken, Task<TOut>>Async function to execute when the error is an UnexpectedError.
onErrorFunc<Error, CancellationToken, Task<TOut>>Default async function to execute for any other error type.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task<TOut>
A task that represents the asynchronous operation. The task result contains the output from the appropriate handler function.
Type Parameters
TInType of the result value.
TOutType of the output.
MatchErrorAsync<TIn, TOut>(Task<Result<TIn>>, Func<TIn, CancellationToken, Task<TOut>>, Func<ValidationError, CancellationToken, Task<TOut>>?, Func<NotFoundError, CancellationToken, Task<TOut>>?, Func<ConflictError, CancellationToken, Task<TOut>>?, Func<BadRequestError, CancellationToken, Task<TOut>>?, Func<UnauthorizedError, CancellationToken, Task<TOut>>?, Func<ForbiddenError, CancellationToken, Task<TOut>>?, Func<DomainError, CancellationToken, Task<TOut>>?, Func<RateLimitError, CancellationToken, Task<TOut>>?, Func<ServiceUnavailableError, CancellationToken, Task<TOut>>?, Func<UnexpectedError, CancellationToken, Task<TOut>>?, Func<Error, CancellationToken, Task<TOut>>?, CancellationToken)
Asynchronously pattern matches on the result with async handlers for different error types.
public static Task<TOut> MatchErrorAsync<TIn, TOut>(this Task<Result<TIn>> resultTask, Func<TIn, CancellationToken, Task<TOut>> onSuccess, Func<ValidationError, CancellationToken, Task<TOut>>? onValidation = null, Func<NotFoundError, CancellationToken, Task<TOut>>? onNotFound = null, Func<ConflictError, CancellationToken, Task<TOut>>? onConflict = null, Func<BadRequestError, CancellationToken, Task<TOut>>? onBadRequest = null, Func<UnauthorizedError, CancellationToken, Task<TOut>>? onUnauthorized = null, Func<ForbiddenError, CancellationToken, Task<TOut>>? onForbidden = null, Func<DomainError, CancellationToken, Task<TOut>>? onDomain = null, Func<RateLimitError, CancellationToken, Task<TOut>>? onRateLimit = null, Func<ServiceUnavailableError, CancellationToken, Task<TOut>>? onServiceUnavailable = null, Func<UnexpectedError, CancellationToken, Task<TOut>>? onUnexpected = null, Func<Error, CancellationToken, Task<TOut>>? onError = null, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<TIn>>The task representing the result to match on.
onSuccessFunc<TIn, CancellationToken, Task<TOut>>Async function to execute on success.
onValidationFunc<ValidationError, CancellationToken, Task<TOut>>Async function to execute when the error is a ValidationError.
onNotFoundFunc<NotFoundError, CancellationToken, Task<TOut>>Async function to execute when the error is a NotFoundError.
onConflictFunc<ConflictError, CancellationToken, Task<TOut>>Async function to execute when the error is a ConflictError.
onBadRequestFunc<BadRequestError, CancellationToken, Task<TOut>>Async function to execute when the error is a BadRequestError.
onUnauthorizedFunc<UnauthorizedError, CancellationToken, Task<TOut>>Async function to execute when the error is an UnauthorizedError.
onForbiddenFunc<ForbiddenError, CancellationToken, Task<TOut>>Async function to execute when the error is a ForbiddenError.
onDomainFunc<DomainError, CancellationToken, Task<TOut>>Async function to execute when the error is a DomainError.
onRateLimitFunc<RateLimitError, CancellationToken, Task<TOut>>Async function to execute when the error is a RateLimitError.
onServiceUnavailableFunc<ServiceUnavailableError, CancellationToken, Task<TOut>>Async function to execute when the error is a ServiceUnavailableError.
onUnexpectedFunc<UnexpectedError, CancellationToken, Task<TOut>>Async function to execute when the error is an UnexpectedError.
onErrorFunc<Error, CancellationToken, Task<TOut>>Default async function to execute for any other error type.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task<TOut>
A task that represents the asynchronous operation. The task result contains the output from the appropriate handler function.
Type Parameters
TInType of the result value.
TOutType of the output.
MatchErrorAsync<TIn, TOut>(Task<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<Error, TOut>?)
Asynchronously pattern matches on the result, with specific handlers for different error types.
public static Task<TOut> MatchErrorAsync<TIn, TOut>(this Task<Result<TIn>> resultTask, Func<TIn, TOut> onSuccess, Func<ValidationError, TOut>? onValidation = null, Func<NotFoundError, TOut>? onNotFound = null, Func<ConflictError, TOut>? onConflict = null, Func<BadRequestError, TOut>? onBadRequest = null, Func<UnauthorizedError, TOut>? onUnauthorized = null, Func<ForbiddenError, TOut>? onForbidden = null, Func<DomainError, TOut>? onDomain = null, Func<RateLimitError, TOut>? onRateLimit = null, Func<ServiceUnavailableError, TOut>? onServiceUnavailable = null, Func<UnexpectedError, TOut>? onUnexpected = null, Func<Error, TOut>? onError = null)
Parameters
resultTaskTask<Result<TIn>>The task representing the result to match on.
onSuccessFunc<TIn, TOut>Function to execute on success.
onValidationFunc<ValidationError, TOut>Function to execute when the error is a ValidationError.
onNotFoundFunc<NotFoundError, TOut>Function to execute when the error is a NotFoundError.
onConflictFunc<ConflictError, TOut>Function to execute when the error is a ConflictError.
onBadRequestFunc<BadRequestError, TOut>Function to execute when the error is a BadRequestError.
onUnauthorizedFunc<UnauthorizedError, TOut>Function to execute when the error is an UnauthorizedError.
onForbiddenFunc<ForbiddenError, TOut>Function to execute when the error is a ForbiddenError.
onDomainFunc<DomainError, TOut>Function to execute when the error is a DomainError.
onRateLimitFunc<RateLimitError, TOut>Function to execute when the error is a RateLimitError.
onServiceUnavailableFunc<ServiceUnavailableError, TOut>Function to execute when the error is a ServiceUnavailableError.
onUnexpectedFunc<UnexpectedError, TOut>Function to execute when the error is an UnexpectedError.
onErrorFunc<Error, TOut>Default function to execute for any other error type.
Returns
- Task<TOut>
A task that represents the asynchronous operation. The task result contains the output from the appropriate handler function.
Type Parameters
TInType of the result value.
TOutType of the output.
SwitchErrorAsync<TIn>(Task<Result<TIn>>, Func<TIn, CancellationToken, Task>, Func<ValidationError, CancellationToken, Task>?, Func<NotFoundError, CancellationToken, Task>?, Func<ConflictError, CancellationToken, Task>?, Func<BadRequestError, CancellationToken, Task>?, Func<UnauthorizedError, CancellationToken, Task>?, Func<ForbiddenError, CancellationToken, Task>?, Func<DomainError, CancellationToken, Task>?, Func<RateLimitError, CancellationToken, Task>?, Func<ServiceUnavailableError, CancellationToken, Task>?, Func<UnexpectedError, CancellationToken, Task>?, Func<Error, CancellationToken, Task>?, CancellationToken)
Asynchronously executes different actions based on the result state and error type.
public static Task SwitchErrorAsync<TIn>(this Task<Result<TIn>> resultTask, Func<TIn, CancellationToken, Task> onSuccess, Func<ValidationError, CancellationToken, Task>? onValidation = null, Func<NotFoundError, CancellationToken, Task>? onNotFound = null, Func<ConflictError, CancellationToken, Task>? onConflict = null, Func<BadRequestError, CancellationToken, Task>? onBadRequest = null, Func<UnauthorizedError, CancellationToken, Task>? onUnauthorized = null, Func<ForbiddenError, CancellationToken, Task>? onForbidden = null, Func<DomainError, CancellationToken, Task>? onDomain = null, Func<RateLimitError, CancellationToken, Task>? onRateLimit = null, Func<ServiceUnavailableError, CancellationToken, Task>? onServiceUnavailable = null, Func<UnexpectedError, CancellationToken, Task>? onUnexpected = null, Func<Error, CancellationToken, Task>? onError = null, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<TIn>>The task representing the result to switch on.
onSuccessFunc<TIn, CancellationToken, Task>Async action to execute on success.
onValidationFunc<ValidationError, CancellationToken, Task>Async action to execute when the error is a ValidationError.
onNotFoundFunc<NotFoundError, CancellationToken, Task>Async action to execute when the error is a NotFoundError.
onConflictFunc<ConflictError, CancellationToken, Task>Async action to execute when the error is a ConflictError.
onBadRequestFunc<BadRequestError, CancellationToken, Task>Async action to execute when the error is a BadRequestError.
onUnauthorizedFunc<UnauthorizedError, CancellationToken, Task>Async action to execute when the error is an UnauthorizedError.
onForbiddenFunc<ForbiddenError, CancellationToken, Task>Async action to execute when the error is a ForbiddenError.
onDomainFunc<DomainError, CancellationToken, Task>Async action to execute when the error is a DomainError.
onRateLimitFunc<RateLimitError, CancellationToken, Task>Async action to execute when the error is a RateLimitError.
onServiceUnavailableFunc<ServiceUnavailableError, CancellationToken, Task>Async action to execute when the error is a ServiceUnavailableError.
onUnexpectedFunc<UnexpectedError, CancellationToken, Task>Async action to execute when the error is an UnexpectedError.
onErrorFunc<Error, CancellationToken, Task>Default async action to execute for any other error type.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
TInType of the result value.