[英]How to show body of a bad request response in angular 4?
To provide login error message I added a message in the constructor of Bad Request Response which shows in the postman while testing an web api. 为了提供登录错误消息,我在Bad Request Response的构造函数中添加了一条消息,该消息在测试Web api时显示在邮递员中。 Like this: return BadRequest("Error Message");
像这样:return BadRequest(“ Error Message”); Now I want to get that message and display in a component in the client side.
现在,我想获取该消息并显示在客户端的组件中。 But I don't know how to retrieve that.
但我不知道该如何检索。 I am trying like this:
我正在这样尝试:
signIn() {
this.authService.login(this.loginCredentials).subscribe(result=>{
if(result){
let returnUrl=this.route.snapshot.queryParamMap.get('returnUrl');
this.router.navigate([returnUrl||'/']);
}
},
(err) => {
this.loginMessage=true;
console.log(err.body);
this.invalidLogin=true;
});
} }
Finally got it. 终于明白了。 It will be
这将是
console.log(err.body);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.