我订购了一个服务,我从外部API请求图像URL并将其存储在共享服务中。我的订阅没有处理错误
逻辑:
1.清空当前图像阵列从API
2.请求图像,并且将其推到(新清除的)阵列(响应=>)
3.如果URL返回一个错误,使用默认(占位符)图像填充阵列(错误=>)
由于某些原因,尽管存在错误,但仍未处理该错误。 我已发布我的组件和错误消息的上下文。
Component.ts
getImages(vehicleID: number, color: string): void {
this._carConfigService.car.colors.exterior.urls = [];
this._FAPIService.getImagesForColors(vehicleID, color)
.subscribe(
response => {
response.products[0].productFormats.forEach(pF => {
this._carConfigService.car.colors.exterior.urls.push(pF.assets[0].url);
});
},
error => {
this.errorMessage = <any>error;
if (this._carConfigService.car.colors.exterior.urls.length === 0) {
this._carConfigService.car.colors.exterior.urls = this._carConfigService.defaultImages;
}
});
}
我收到以下错误:
Failed to load resource: the server responded with a status of 422()
EXCEPTION: Response with status: 0 for URL: null
Uncaught Response
你可以用'onCatch'方法处理错误,你写的服务,然后地图后扔那么你的用户将能够处理它 –
@BabarBilal,这可能是我在寻找解决方案因为,你可以发布一个示例代码片段,以便我可以将你的答案标记为正确吗?谢谢:) – Moshe
Im从手机不能发布代码段添加2个链接都有解决您的问题祝您好运。 –