a Put Action is defined with a parameter type int and I need to respond a custom BadRequest message when a string is sent instead, this response should be only for one Controller
[HttpPut("address")]
[Authorize]
[ProducesResponseType(typeof(Customer), 200)]
[ProducesResponseType(typeof(Error), 400)]
[ProducesResponseType(typeof(Error), 404)] //custom error
[ProducesDefaultResponseType]
public async Task<IActionResult> UpdateAddress(
[Required] [FromForm] string email,
[Required] [FromForm] string address_1,
[FromForm] string address_2,
[Required] [FromForm] string city,
[Required] [FromForm] string region,
[Required] [FromForm] string postal_code,
[Required] [FromForm] string country,
[Required] [FromForm] int shipping_region_id //this is the parameter to validate
)
{
//...
}
the BadRequest (400) message should be : "The Shipping Region ID is not number" How I can validate the type before to reach the Controller and send a custom BadRequest object?