Reputation: 93
I am currently working on Asp.net WebAPI2 Project. I am making a custom method for returning custom HttpStatusCode for error handling.
here's my code
public IHttpActionResult GetError(int errCode) {
int ErrCode = errCode * -1;
ResourceManager ResourceManager = new ResourceManager("PIJ.API.OWIN.Properties.Resources", Assembly.GetExecutingAssembly());
string ErrorMessage = ResourceManager.GetString("_" + ErrCode.ToString());
return Content((HttpStatusCode)ErrCode, new HttpError(ErrorMessage));
}
my current output is like this Output Screenshot
my question is. Is is possible to return only the HttpStatusCode, without the error Message ?
Thank you very much.
Upvotes: 0
Views: 75
Reputation: 37918
You can return StatusCodeResult
with required HttpStatusCode
. This can be done using StatusCode
method of ApiController
public IHttpActionResult Test()
{
return StatusCode(HttpStatusCode.BadRequest);
}
Upvotes: 1