mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 00:57:09 +01:00
toast changes
This commit is contained in:
parent
689b0db1a8
commit
a89eaafed7
6 changed files with 35 additions and 17 deletions
|
|
@ -3,15 +3,18 @@ import {
|
|||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
HttpInterceptor,
|
||||
HttpErrorResponse
|
||||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { AuthService } from './auth.service';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Toast, ToastService } from './toast.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private authService: AuthService) {}
|
||||
constructor(private authService: AuthService, private toastService: ToastService) {}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
if (this.authService.isAuthenticated()) {
|
||||
|
|
@ -21,6 +24,14 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||
}
|
||||
});
|
||||
}
|
||||
return next.handle(request);
|
||||
return next.handle(request).pipe(
|
||||
catchError((error: HttpErrorResponse) => {
|
||||
if (error.status == 401 && this.authService.isAuthenticated()) {
|
||||
this.authService.logout()
|
||||
this.toastService.showToast(Toast.makeError("Your session has expired. Please log in again."))
|
||||
}
|
||||
return throwError(error)
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue