Add a control to avoid error notif at login failure.

This commit is contained in:
2020-01-18 14:30:17 +01:00
parent 84b1dd6352
commit 5e5fbd9377

View File

@@ -6,6 +6,8 @@ import { catchError } from 'rxjs/operators';
import { AuthService } from '../services/auth.service';
import { NotificationsComponent } from '../notifications/notifications.component';
const REG_URL_LOGIN = /^https?:\/\/.*(:\d{1,5})?\/api\/account\/login$/;
@Injectable()
export class UnauthorizedInterceptor implements HttpInterceptor {
constructor(
@@ -18,8 +20,10 @@ export class UnauthorizedInterceptor implements HttpInterceptor {
if (err.status === 401) {
this.authService.setAnonymous();
this.router.navigate(['/login']);
if (!err.url.match(REG_URL_LOGIN)) {
window.setTimeout(() => NotificationsComponent.error('Veuillez vous authentifier pour réaliser cette action.'), 500);
}
}
const error = (err.error && err.error.message) || err.statusText;
return throwError(error);