I use .NET 8 and I have minimal API in ApsNetCore. I have this GET method with param bindings using StronglyTypedId:
internal static async Task<Results<Ok<PaginatedList<TestResultDto>>, BadRequest<string>, NotFound>> Handle(
[AsParameters] GetTestResultsRequest request,
IValidator<GetTestResultsRequest> validator)
{
..some code..
}
and
public record GetTestResultsRequest(
PatientProfileId? PatientProfileId,
...
where:
[StronglyTypedId]
public readonly partial struct PatientProfileId;
My problem is that when a client is sending a request with improper Guid:
https://localhost:7158/v1/test_results?PatientProfileId=df8537ab
I get a response as internal server error:
{
"type": "https://www.rfc-editor.org/rfc/rfc9110.html#name-500-internal-server-error",
"title": "Internal Server Error",
"status": 500
}
Clearly it is a Client error instead 4xx, so how can I catch these type of errors and change the response error?
thanks