Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 订阅错误,未命中HttpClient调用_Typescript_Rxjs_Angular6 - Fatal编程技术网

Typescript 订阅错误,未命中HttpClient调用

Typescript 订阅错误,未命中HttpClient调用,typescript,rxjs,angular6,Typescript,Rxjs,Angular6,当我的API返回错误(例如:状态代码400)时,订阅上的错误不会被命中。我已经将我的httpclient调用包装在一个名为RestDataService的服务中,所有服务都可以使用该服务进行基于REST的调用 然后我有另一个名为SampleService的服务,它注入RestDataService,并有一个名为uploadFile的方法,该方法调用我的api端点 因此,一旦我将服务注入CallingClass并从服务调用uploadMap,错误句柄就不会触发。我不太清楚为什么 @可注入({ pr

当我的API返回错误(例如:状态代码400)时,订阅上的错误不会被命中。我已经将我的httpclient调用包装在一个名为RestDataService的服务中,所有服务都可以使用该服务进行基于REST的调用

然后我有另一个名为SampleService的服务,它注入RestDataService,并有一个名为uploadFile的方法,该方法调用我的api端点

因此,一旦我将服务注入CallingClass并从服务调用uploadMap,错误句柄就不会触发。我不太清楚为什么

@可注入({
providedIn:'根'
})
导出类RestDataService{
构造函数(私有httpClient:httpClient){
}
公共帖子(URL:string,data:any):可观察{
返回此.httpClient.post(URL,数据,{withCredentials:environment.withCredentials})
.pipe(catchError(err=>this.handleError('post:'+URL,err));
}
私有句柄错误(url:string,err:any){
console.error('RestDataService服务器错误:',err);
if(HttpErrorResponse的错误实例){
让errMsg:string;
const errDetail=JSON.stringify(err.error);
errMsg=`${err.status}-${err.statusText | |''''}URL:${URL}消息:${err.Message}详细信息:${errDetail};
返回抛出器错误(新错误(errMsg));
}
返回抛出器错误(错误| |“RestDataService服务器错误”);
}
}
@注射的({
providedIn:'根'
})
导出类示例服务{
构造函数(restDataService:restDataService){
const BASE_URL=environment.Endpoint;
super(restDataService,BASE_URL);
}
公共上传地图(数据:任意):可观察{
const URL=this.BASE_URL+'par/;
返回此.restDataService.post(URL,数据);
}
}
导出类调用类{
构造函数(私有服务:服务,私有dialogRef:MatDialogRef){}
公共上载映射(xml:any){
常数数据={
xmlFile:window.btoa(xml)
};
this.service.upLoadMap(data.subscribe(parseData=>{
this.dialogRef.close({data:parseData});
},
(错误)=>{
控制台日志(err);
this.dialogRef.close();
});
}
}

我刚刚玩了一个catchError游戏,订阅抛出了一个异常“TypeError:您在预期流的位置提供了“undefined”。您可以提供可观察、承诺、数组或Iterable。”

const{throwError}=rxjs;
const{catchError}=rxjs.operators;
抛掷器(“错误”)。管道(
catchError(err=>{console.log(`From catchError:${err}`);})
).subscribe(val=>{console.log(val);},err=>{console.log(`From sub:${err}');})

谢谢你,阿德里安。我试图将.pipe(tap(未定义,err=>{console.log(
From tap:${err}
);}))添加到我的CallingClass中,但当http响应为400时,它从未命中。