0

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

4
  • why do you think it's a client error? Commented Jul 12, 2024 at 20:32
  • if the param is not a Guid then it is a Client error. What else? Commented Jul 13, 2024 at 12:12
  • I think what browsermator concerned is how a client report 500 error, he might think this shall be a server error. Anyway, I think this document about how to handle errors in minimal API shall be helpful here. Commented Jul 15, 2024 at 2:09
  • thanks, I solved by creating a global exception handler and parsing the error type. If it is client type error then I use the 4xx code. Commented Jul 15, 2024 at 15:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.