I am porting an API from ASP .NET 4.7 to .NET CORE 3.1 and so far I have managed to get most of the work done, but I got stuck at a specific error. I have the following endpoint
[HttpGet]
[Route("contacts/{id}/")]
public IActionResult GetContactByID(Guid? id)
{
if (!id.HasValue)
return BadParameter("id");
//Some irrelevant logic here
Contact foundContact = GetContactFromRepository(id);
return Ok(foundContact);
}
By providing an invalid Guid ("contacts/6cb735b1-b2f0-45d1-a5b5-3a161a5b8c5eTESTINVALIDGUID") in the old API - the endpoint would be reached and the IF statement checking if ID has value would provide the expected error response format. Currently in CORE 3.1 when In identical request I am getting the following response in Postman:
"errors": {
"id": [
"The value '6cb735b1-b2f0-45d1-a5b5-3a1615555555asd' is not valid."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|90331587-428887e84126845c."
The execution never reaches the method. But the constructor of the controller gets called.
I have overwritten most of the error messages and I am porting multiple API versions in the same time ( with different responses for each ). But I cannot figure out where this error is coming from ( and how to handle it so the request actually reaches the controller method - so that I can return the correct response ).