将HttpErrorResponse值解析为JSON对象

技术:

我有以下 HttpErrorResponse

在此处输入图片说明

我需要value通过解析JSON对象属性获取状态和消息

我尝试了以下

this.http.request(uploadReq).subscribe(event => {
      if (event.type === HttpEventType.UploadProgress)
        this.progress = Math.round(100 * event.loaded / event.total);
      if (this.progress == 100) {
        this.uploadeda = true;
        this.error = false;
      }
      else if (event.type === HttpEventType.Response)
        this.message = event.body.toString();

    }, err => { console.error(JSON.parse(err.value.toString()).status);});

我不断收到以下错误

ERROR TypeError: Cannot read property 'toString' of undefined
Jobelle:

您无需解析错误响应。同样,该值在错误对象内部。所以err.error.value会给你期望的

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章