Fix interceptor for unauthorized http response (#27)
This commit is contained in:
parent
069006145a
commit
c361143ba2
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the frozen screen if the token has expired
|
||||||
- Fixed some issues in the generic scraper
|
- Fixed some issues in the generic scraper
|
||||||
|
|
||||||
## 0.87.0 - 19.04.2021
|
## 0.87.0 - 19.04.2021
|
||||||
|
@ -45,21 +45,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
authReq = req.clone({ headers });
|
authReq = req.clone({ headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
return next.handle(authReq).pipe(
|
return next.handle(authReq);
|
||||||
tap(
|
|
||||||
() => {},
|
|
||||||
(err: any) => {
|
|
||||||
if (err instanceof HttpErrorResponse) {
|
|
||||||
if (err.status !== 401) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tokenStorageService.signOut();
|
|
||||||
this.router.navigate(['start']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,15 +15,21 @@ import {
|
|||||||
MatSnackBarRef,
|
MatSnackBarRef,
|
||||||
TextOnlySnackBar
|
TextOnlySnackBar
|
||||||
} from '@angular/material/snack-bar';
|
} from '@angular/material/snack-bar';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
import { StatusCodes } from 'http-status-codes';
|
import { StatusCodes } from 'http-status-codes';
|
||||||
import { Observable, throwError } from 'rxjs';
|
import { Observable, throwError } from 'rxjs';
|
||||||
import { catchError, tap } from 'rxjs/operators';
|
import { catchError, tap } from 'rxjs/operators';
|
||||||
|
import { TokenStorageService } from '../services/token-storage.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HttpResponseInterceptor implements HttpInterceptor {
|
export class HttpResponseInterceptor implements HttpInterceptor {
|
||||||
public snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
|
public snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
|
||||||
|
|
||||||
public constructor(private snackBar: MatSnackBar) {}
|
public constructor(
|
||||||
|
private router: Router,
|
||||||
|
private tokenStorageService: TokenStorageService,
|
||||||
|
private snackBar: MatSnackBar
|
||||||
|
) {}
|
||||||
|
|
||||||
public intercept(
|
public intercept(
|
||||||
request: HttpRequest<any>,
|
request: HttpRequest<any>,
|
||||||
@ -70,6 +76,9 @@ export class HttpResponseInterceptor implements HttpInterceptor {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if (error.status === StatusCodes.UNAUTHORIZED) {
|
||||||
|
this.tokenStorageService.signOut();
|
||||||
|
this.router.navigate(['start']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return throwError('');
|
return throwError('');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user