我有以下 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
您无需解析错误响应。同样,该值在错误对象内部。所以err.error.value会给你期望的
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句