app.MapPost($"{root}/v1/AuthenticateUser"
, async Task<Results<Ok<GetTokenForResponse>, BadRequest<ErrorModel>>>
(HttpContext httpContext, IMediator mediator, AuthenticateBody body) =>
{
var response = await mediator.Send(new AuthenticateUserHandler.Request(httpContext, body.UserName, body.Password));
if (response.IsSuccessful)
return TypedResults.Ok(response.Result);
return TypedResults.BadRequest(response.Error);
})
.WithTags(root);
I am currently running on .NET 7
I am not finding any clues as to why the BadRequest
method will NOT return the body
Results.BadRequest Method on MS Docs
似乎这应该返回在GET GO中定义的任何对象.但出于某种原因,事实并非如此.100
public record BaseResponse<T>
{
public HttpContext? HttpContext { get; set; }
public bool IsSuccessful => Error is null && Result is not null;
public ErrorModel? Error { get; set; }
public T? Result { get; set; }
}
在本例中,T
属于一个名为GetTokenFor_Response
的类.Ok
路径返回有效的正文.BadRequest
并非如此.
NOTE: Adding screenshot of Response object coming back from Mediatr:
注2: 问题在Github点开始.
NOTE 3: Changed the Error object like this and it now works. The error was not in the BadRequest method per se. It was a record that did not have public getters? I think?