为什么在服务器关闭时无法捕获Angular中的HTTP错误?
我的Angular 9中有一个REST服务来处理所有HTTP请求。关闭REST服务器时,为什么在服务器关闭时无法捕获Angular中的HTTP错误?,angular,rxjs,angular-httpclient,angular-http,Angular,Rxjs,Angular Httpclient,Angular Http,我的Angular 9中有一个REST服务来处理所有HTTP请求。关闭REST服务器时,console.log()中存在错误,但我无法在服务中捕获它们: return this.http.post<any[]>(this.path, data, header).pipe( catchError((err: HttpErrorResponse) => { console.log("---", err); r
console.log()
中存在错误,但我无法在服务中捕获它们:
return this.http.post<any[]>(this.path, data, header).pipe(
catchError((err: HttpErrorResponse) => {
console.log("---", err);
return of(null);
})
);
为什么会发生这种情况,为什么会忽略
catchError
?您将在catchError中获得与http调用相关的错误。在这种情况下,您的呼叫甚至没有到达任何服务器。为了捕获这些类型的错误,您可以通过实现ErrorHandler接口来设置全局错误处理程序。请参阅下面的链接以进行此操作:-
您将在catchError中获得与http调用相关的错误。在这种情况下,您的呼叫甚至没有到达任何服务器。为了捕获这些类型的错误,您可以通过实现ErrorHandler接口来设置全局错误处理程序。请参阅下面的链接以进行此操作:-
如果你没有在catchError()中捕捉到它,那就太奇怪了。错误应该在rxjs的catchError()方法中显示。@Talg123这正是我的问题,因为我不明白为什么会发生这种情况。这可能是因为请求甚至没有通过,也没有返回,即处理当时就停止了。你有没有试过在一个
HttpInterceptor
中捕捉错误?Manish说,如果你没有在catchError()中捕捉到它,你的请求就会被HttpInterceptor阻止,这很奇怪。错误应该在rxjs的catchError()方法中显示。@Talg123这正是我的问题,因为我不明白为什么会发生这种情况。这可能是因为请求甚至没有通过,也没有返回,即处理当时就停止了。您是否尝试过捕获HttpInterceptor中的错误?Manish说,您的请求被HttpInterceptor阻止了
zone-evergreen.js:2845 HEAD https://SERVER/ net::ERR_CERT_COMMON_NAME_INVALID