I use WebApi 2 and have an idea to use own status codes (from 452 till 499) for bad request.
i.e: user has no required role - code is 452, operation is not completed by reason #1 - code is 453, by reason #2 - code is 454 etc...
Problem is I return HttpResponseMessage
and it allows to return only HttpStatusCode
enumeration, which has only pre-defined (standard) status codes
public async Task<HttpResponseMessage> PasswordRecoveryAsync(PasswordRecoveryApiModel model)
{
var user = await UserManager.FindByNameAsync(model.Username);
if (user == null)
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "User with such username is not found");
if (user.AspNetRoles.Where(p=>p.Name == Models.Roles.Editorial).Count() == 0)
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "...")
....
return Request.CreateResponse<string>(HttpStatusCode.OK, "Confirmation token is sent to your email");
}
Is my idea good or not? If good, then how do I solve it?