Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

23 строки
908 B

  1. import { Injectable } from '@angular/core';
  2. import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
  3. import { Observable, throwError } from 'rxjs';
  4. import { catchError } from 'rxjs/operators';
  5. import { AccountService } from '@app/_services';
  6. @Injectable()
  7. export class ErrorInterceptor implements HttpInterceptor {
  8. constructor(private accountService: AccountService) {}
  9. intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  10. return next.handle(request).pipe(catchError(err => {
  11. if ([401, 403].includes(err.status) && this.accountService.userValue) {
  12. // auto logout if 401 or 403 response returned from api
  13. this.accountService.logout();
  14. }
  15. const error = err.error?.message || err.statusText;
  16. return throwError(() => error);
  17. }))
  18. }
  19. }