我们正在使用httpClient和withCredentials:true开发Angular 6应用程序。当我们向同一服务器上的另一个端口(从端口8010到8011)发出请求时,Firefox会尝试发出预检请求。但似乎我们的有角度的httpClient试图处理此预检响应。我们正在使用以下代码。我们看到,流程正在进入catchError块。为什么angular-httpclient处理飞行前响应?我们该如何处理?
request(url: string, method: string, options?: any, xmlOptions?: any,
isFullUrl:boolean = false): Observable<any> {
const fullUrl = (isFullUrl) ? url : `${HttpService.BASE_URL}${url}`;
return this.httpClient.request(method, fullUrl, options).pipe(
map(resp => this.parseXML(resp, xmlOptions)),
catchError(exception => this.processError(exception, xmlOptions))
);
}
private processError(exception, xmlOptions) {
this.notificationService.clear();
this.notificationService.error(HttpService.UNEXPECTED_ERROR_OCCURRED);
if(exception.error) {
let errorObj = this.parseXML(exception.error, xmlOptions);
return throwError(errorObj);
}
else {
return throwError(exception);
}
}
如果我们检查异常,则错误消息为"Http failure response for (unknown url): 0 Unknown Error"
注意:这在Chrome浏览器中工作正常。