I have an angular app which send a login request to the server and gets back an error which I throw from the server in case the username or password are invalid or incorrect. Anyway, I have a function on the $http service that gets the error message, but for some reason, the error message comes as a long string of HTML tags and the Exception I throw is somewhere inside that HTML. I want to be able to get the raw message without the customizations or whatever you'd call it, that the server or browser do.
I'll appreciate any help from you.
Update:
My mistake was that I threw Exceptions on my server instead of returning an error. Now I fixed it and i'm returning Errors but I want to return also a status code or a some proper 'http response message'. The method SetError does not allow me this. Is there any other way to do that?
Here is my method:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (AuthRepository _repo = new AuthRepository())
{
bool user = _repo.Authenticate(context.UserName, context.Password);
if (user == false)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
context.Validated(identity);
}