angular - 将 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
解决方案
您不需要解析错误响应。此外,该值位于错误对象内。所以 err.error.value 会给你预期的
推荐阅读
- vb.net - 在 vb.net 中加载带有 100 个空行的 DataGridView,其中行号为
- r - ggplot 地图图例显示不一致
- node.js - 节点调度器重复
- django - Django-Channels AsyncConsumer 不工作
- optimization - 找到得分最高的非重叠序列的子集
- typescript - 为什么我可以使用临时变量来解决 TypeScript 的对象字面量赋值约束?
- ejb - JCA 远程队列 Wildfly Artemis
- silverstripe - 切换主题后无法访问编辑器
- react-native - React Native:将图像并排对齐在一行上,并具有动态数量的图像
- javascript - 短回调函数语法背后的原理