首页 > 解决方案 > 如何访问 HttpErrorResponse 的特定属性?

问题描述

我有以下 HttpErrorResponse 并且我想访问 msg 属性。我怎样才能访问它,以便我可以打印出来?

它来自失败的 http 调用,我知道失败的原因,但我想为用户打印出来。

我的 HttpErrorResponse

标签: angularhttp

解决方案


我认为这就是你想要实现的。

this.yourHttpRequest().subscribe(
res => somethingOnSuccess, 
httpErrorResponse => {
   // here you have your object from HttpErrorResponse
   console.log(httpErrorResponse);
   console.log(httpErrorResponse.error[0].msg);
});

推荐阅读