将此aurelia -auth 插件与 .NET Core webAPI 一起使用,我希望在用户尝试使用不正确的用户名和/或密码登录时返回自定义错误。
网络接口:
public HttpResponseMessage Login()
{
if (passwordValid)
{
return Request.CreateResponse(new LoginResponseViewModel { Token = token });
}
else
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Incorrect username or password!");
}
}
脚本
logIn(email, password) {
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(err => {
console.log("login failure: " + err);
});
}
- 如何在登录功能捕获错误时访问我未经授权的响应自定义消息“用户名或密码错误”?
- 似乎 aurelia-auth 登录功能必须接收一个
httpStatusCode.Unauthorized
才能使其了解密码/用户名不正确,但这会产生401 (Unauthorized)
控制台错误。我可以抑制这个控制台错误或者返回一个 aurelia-auth 可以理解的 json 结果吗?