根据HttpResponse的内容,我想抛出一个被globalErrorHandler捕获的错误:ErrorHandler。
我的globalError处理程序对于每种错误都可以正常工作,除了这种错误。
我在拦截器中尝试过 https://angular.io/api/common/http/HttpInterceptor
@Injectable({
providedIn: 'root'
})
export class ErrorInterceptor implements HttpInterceptor {
constructor(private router: Router) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse && this.isTechnicalError(event)) {
return throwError(new HttpErrorResponse(req));
}
return event;
}));
}
isTechnicalError(event: HttpResponse<any>) {
}
}
我的errorHandler https://angular.io/api/core/ErrorHandler
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
constructor(private injector: Injector) {
}
handleError(error: Error | HttpErrorResponse) {
// not going here
}
}