angular - 如何在拦截中获得身体反应?
问题描述
我使用最后一个 Angular 并且需要在这里截获正文请求:
return next.handle(request).pipe(
catchError(err => {
return throwError(err);
}))
我试图这样做:
return next.handle(request).pipe(
.map((res: Response) => {
if (res.result.hasOwnProperty('errors')) {
}
return res;
})
catchError(err => {
return throwError(err);
}));
但这对我不起作用
解决方案
而不是map
使用tap
, 来获取响应并执行一些与之相关的操作,而tap
您不需要返回 smth.
return next.handle(request).pipe(
tap(response => {
if (response instanceof HttpResponse) {
console.log(response);
}
}, e => {
console.log(e);
})
)
推荐阅读
- javascript - 检查来自对象javascript的所有数据
- azure - Azure Next.js 部署。所需结构
- docker - 来自容器外部的 Docker ApacheMQ 连接
- apache-kafka - 使用 confluent-kafka-dotnet 连接到外部 Kafka 服务器失败
- c++ - 对带有库 MySQL 服务器和连接器 C++ 的 Eclipse C++ 的未定义引用
- microservices - 断路器作为独立服务
- go - 如何使用 Golang 中的反射将 time.Time 类型的字段的值设置为 time.Now()
- javascript - 如何在带有角度的打字稿中使用动态键访问 JSON 对象值
- blockchain - 如何将 polkadot.js 连接到 Parastate 本地节点
- python - 选择性地抑制 altair 图中的图例