My route template on action method is something like below:
[Route("{select:bool=false}")]
and method signature is public int GetMethod(bool select) {}
Question 1:
I am consuming above endpoint by using following url. I am passing string value to boolean parameter
http://localhost/api/controller?select=lskdfj
I get the following response:
{
"Message": "The request is invalid.",
"MessageDetail": "The parameters dictionary contains a null entry for parameter 'select' of non-nullable type 'System.Boolean' for method 'int GetMethod(Boolean)' in '**ProjectName.Controllers.ControllerName**'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
}
Instead of showing projectName, controller name which are details of our code and also the above message have more details, I want to show some customize message to consumer/client.
Is there a way to do that?
Question 2:
I am consuming above endpoint by using following url. I am passing by giving incorrect parameter name.
http://localhost/api/controller?selt=true
It does not throw error and take the default value of select i.e. false instead of throwing error.
How to throw error message to the client saying the parameter provided (selt) was wrong?