[英]Angular 7 rxjs/forkJoin : You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
[英]Rxjs 6: using catchError() gives You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
我正在使用新語法來遵守RxJS 6 pipe()
。 同樣使用Angular6。我有一個處理http請求的服務,它通過管道連接map和catchError
在連接錯誤的情況下顯示舉杯。 但是,如果我添加catchError
進入控制台, 您在期望流的位置提供了“ undefined”。 您可以提供一個Observable,Promise,Array或Iterable。
getDataHttpRequest(url, returnType) {
return this.http.get(url, this.getRequestOptions())
.pipe(
map((response) => {
if(response){
if (returnType === 'object') {
return response[0] == undefined ? response : response[0];
} else {
return response;
}
}
}),
catchError((error):any => {
if(error instanceof HttpErrorResponse && error.status === 0){
//no connection error(either user has no connection or the server is down)
this.toastr.error('Chequee su conexión e intente de nuevo en unos momentos. Contáctenos para reportar el problema a <a href="mailto:dev@info.com">dev@info.com</a>',"Error de Conexión",{tapToDismiss:true, disableTimeOut: true});
}
throwError(`Connection Error: ${error}`);
})
);
}
如果我刪除catchError
函數,錯誤將在控制台中消失,因此這是斷點代碼。 有什么想法可能有問題嗎?
catchError
的回調需要返回一個Observable(它可能會引發一個異常,我認為也會將其轉換為error
)。
catchError((error):any => {
if (whatever) {
...
return empty(); // just complete
}
return throwError(`Connection Error: ${error}`); // return another `error`
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.