@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor() { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
retry(3),
catchError((error: HttpErrorResponse) => {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {
// client-side error
errorMessage = `Error: ${error.error.message}`;
} else {
// server-side error
errorMessage = `Error Code: ${error.status}nMessage: ${error.message}`;
}
window.alert(errorMessage);
return throwError(error);
}));
}
}
万一我出错了。我想知道重试运算符(重试(3((执行的时间,有人能帮我吗!
retry操作符是在您出现错误时触发的,您只需要计算错误的数量。这是的一个例子