我訂購了一個服務,我從外部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個鏈接都有解決您的問題祝您好運。 –