public static IResult ToHttpResult<T, TError>(
this Result<T, TError> result,
int errorStatusCode = StatusCodes.Status400BadRequest,
string? errorTitle = null)
Converts a Result<T, TError> into 200 OK on Ok, or an RFC 7807 ProblemDetails response with errorStatusCode on Err.
Type Parameters
T- The success payload type.
TError- The error value type.
Parameters
result- The result to convert.
errorStatusCode- The HTTP status code used when
result is Err. Defaults to 400 Bad Request.
errorTitle- Optional problem title override for
Err responses.
Returns: An ASP.NET Core IResult.
public static IResult ToHttpResult<T, TError>(
this Result<T, TError> result,
Func<TError, IResult> onError)
Converts a Result<T, TError> into 200 OK on Ok, or delegates error formatting to onError on Err.
public static IResult ToHttpResult<T, TError>(
this Result<T, TError> result,
Func<T, IResult> onOk,
Func<TError, IResult> onError)
Converts a Result<T, TError> into an IResult using explicit onOk and onError mappers.
public static IResult ToProblemResult<T, TError>(
this Result<T, TError> result,
Func<TError, int> statusCodeSelector,
Func<TError, string>? titleSelector = null)
Converts a Result<T, TError> into 200 OK on Ok, or an RFC 7807 ProblemDetails response whose HTTP status code (and optional title) is derived from the error.
public static IResult ToHttpResult<T>(this Option<T> option, string? notFoundDetail = null)
Converts an Option<T> into 200 OK on Some, or 404 Not Found on None. When notFoundDetail is supplied, None returns an RFC 7807 404 ProblemDetails payload.