I would like to store my Http status and them messages in json file, for example BadRequest status could have 2 different messages: 1. name could not be null , 2. name could not be empty and etc... but unfortunatelly I can't solve it, because IHttpActionResult requires to return only status method, how can I add custom message in different case? I am geeting error
Cannot implicitly convert type 'System.Net.Http.StringContent' to 'System.Web.Http.IHttpActionResult'. An explicit conversion exists (are you missing a cast?) Exceptions class:
public class ExceptionResponse
{
public HttpStatusCode ReturnCode { get; set; }
public string Message { get; set; }
}
post method:
[HttpPost]
public IHttpActionResult Post([FromBody] MyRequest myCaseRequest)
{
var myObj = new MyObjCase();
ExceptionResponse data = new ExceptionResponse()
{
Message = "Parameter cannont be null",
ReturnCode = HttpStatusCode.BadRequest
};
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
var jsonCont = new StringContent(json, Encoding.UTF8, "application/json");
if (myObj.Name == null || myObj.Name == "")
// return BadRequest(); // Before
return jsonCont; // expecting for result
}
}