How to replace a 400 error message with a custom message
I am building a webapi and just wondering if I can replace the default error message in the case of 400 Bad Request.
For example, in this url ( http: // localhost / api / values / 4 ) 4 is an integer type, but if I pass in a string intentionally (for example http: // localhost: 35453 / api / values / sss ) I get error message (400 Bad Request) in the following format:
{"Message": "Request is invalid.", "MessageDetail": "The parameter dictionary contains a null entry for the" id "parameter of non-nullable type" System.Int32 "for the" System.Web.Http.IHttpActionResult Get (Int32) "method in "WebAp__DELETE.Controllers.ValuesController". The optional parameter must be a reference type, type null, or declared as an optional parameter. " }
Is there a way to replace this default error message with my own error message.
source to share
No one has answered this question yet
Check out similar questions: