【问题标题】:Angular get exception text from spring bootAngular 从 Spring Boot 获取异常文本
【发布时间】:2020-05-07 15:48:34
【问题描述】:
        this.apiServiceService.generateToken(authRequest).subscribe(
          data => {}, 
          err => {
            console.log(err.error);
        })

; }

输出是

{"timestamp":"2020-05-07T16:08:16.133+0000","status":500,"error":"Internal Server Error","message":"Bad credentials!","path":"/api/authenticate"}

我可以只从这个输出中得到消息吗?谢谢

【问题讨论】:

  • 你试过了吗:err.error.message?

标签: angular spring-boot exception


【解决方案1】:

不确定您是否正在寻找这个,只需使用console.log(err.error.message); 来获取正在打印的消息。

var err = JSON.parse(err.error); 
console.log(err.message);

【讨论】:

  • 这返回未定义,我想从错误输出中得到这个:"message":"Bad credentials!"
  • 你的 console.log(err);打印你。
  • var err = JSON.parse(err.error); console.log(err.message);
猜你喜欢
  • 1970-01-01
  • 2019-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-13
  • 2020-07-23
  • 2019-01-06
  • 2019-12-26
相关资源
最近更新 更多