From: Kai Moritz Date: Mon, 15 Sep 2025 18:53:06 +0000 (+0200) Subject: implemented a faked authentication, that fails in 30% X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=2fefacf53d2bdb938467528ff8aa03d4a25d72eb;p=demos%2Fangular%2Fstored-login implemented a faked authentication, that fails in 30% --- diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index dfd2858..3b4d86a 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,6 +1,6 @@ import { inject, Injectable } from '@angular/core'; import { Router } from "@angular/router"; -import { Observable, of } from 'rxjs'; +import { Observable, of, throwError } from 'rxjs'; @Injectable({ providedIn: 'root' @@ -11,6 +11,11 @@ export class AuthService { private username : string|undefined; login(username : string, password : string) : Observable { + const shouldFail = Math.random() < 0.3; // 30% Fehlerchance + if (shouldFail) { + return throwError(() => new Error('Simulierter Fehler im Service')); + } + this.username = username; return of(username); }