![](/img/trans.png)
[英]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.