Should I always return the same processed JSON object or not
Example:
On the website, the user enters his username and password.
When the user clicks "Submit", he sends a request to /api/logintest/{key}. If the method called by this URL returns a JSON object, for example {errMsg: null} if the user and password match, and {errMsg: "invalid username or password"} if they do not; or should I return and an error message if the user data does not match and do not return the user object in JSON if the user is found?
This is my code.
[ResponseType(typeof(User))]
[HttpPost]
[Route("api/logintest/{key}")]
public IHttpActionResult LoginTest(LoginForm luser , String key)
{
if(key == "jordanisthebest")
{
User userReturn = UsersManager.getUserByEmailAndPassword(new User { Email = luser.Email, Password = luser.Password });
if (userReturn == null)
ModelState.AddModelError("Email", "Bad email or password");
if (!ModelState.IsValid)
return Ok(ModelState.getListErrorAndKey(null, typeof(LoginForm)));
return Ok(userReturn);
}
return NotFound();
}
source
share