외부 API에서 이미지 URL을 요청하여 공유 서비스에 저장하는 서비스에 가입하고 있습니다.내 구독으로 인해 오류가 처리되지 않습니다.
는 는논리는 :
1. 빈 현재 이미지 배열
2. 요청 API의 이미지, 그리고 (새로 클리어) 배열에 밀어 (응답 =>)
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;
}
});
}
나는 다음과 같은 오류가 나타납니다 당신은
export class TaskService {
private _url = "api/products/datanew.json";
constructor(private _http: Http) {
}
getTasks(): Observable<any[]> {
return this._http.get(this._url)
.map((response: Response) => <any[]>response.json())
.do(data => console.log("data we got is " + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(error: Response) {
console.log(error);
return Observable.throw(error.json().error || 'Internal Server error');
}
}
또한 예외 처리를 갖는 규칙적인 접근 방식을 사용하여 처리 할 필요가
Failed to load resource: the server responded with a status of 422()
EXCEPTION: Response with status: 0 for URL: null
Uncaught Response
for, 당신이 정확한 답을 표시 할 수 있도록 샘플 코드 스 니펫을 게시 할 수 있습니까? 고마워 :) –
@BabarBilal, 이것이 내가 찾고 해결책이 될 수 처리 할 수있을 것입니다 당신이 서비스를 쓴 곳 onCatch' 방법 '으로 오류를 처리 한 후지도 후를 던질 수 – Moshe
모바일에서 가져온 코드 스 니펫을 게시 할 수 없다는 점에서 2 개의 링크가 모두 문제의 행운을 해결할 수있는 해결책을 가지고 있습니다. –