I am developing webapi in mvc4. I want to create a class which contains Custom HttpStatusCode
which inherits HttpStatusCode
class. Let's suppose I have one signup
api which require user details like Firstname, Lastname, email, password etc. Suppose user enter email abc@abc.com
and I check if user already exists. If this email is already exists I want to return Custom HttpStatusCode. Suppose I have created 1001 HttpStatusCode
for email already exists.
I tried some thing like this
return new System.Web.Http.Results.ResponseMessageResult(
Request.CreateErrorResponse(
(HttpStatusCode)1001,
new HttpError("Email is already exists.")
)
);
But I don't know is it a correct way or not. When we use return Unauthorized();
it means it's an unauthorized access which returns 401 error code. In same way I want to create a custom response and status code. In my case suppose email id already exists then I should return something like this
return AlreadyExists()
which return 1001 status code. Can I implement such a way? if yes, How can I implement this? can someone please help me?