【发布时间】:2018-06-21 15:52:58
【问题描述】:
我正在使用新语法来遵守 RxJS 6 pipe()。同样使用Angular 6。我有一个处理http请求的服务,它通过管道映射和catchError在连接错误的情况下显示一个toast。不过,如果我添加 catchError 我会进入控制台 您在预期流的位置提供了“未定义”。您可以提供 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 函数,错误会在控制台中消失,因此这是一段代码中断。关于可能出错的任何想法?
【问题讨论】:
标签: angular rxjs angular6 rxjs6