]> juplo.de Git - demos/angular/stored-login/commitdiff
implemented a faked authentication, that fails in 30%
authorKai Moritz <kai@juplo.de>
Mon, 15 Sep 2025 18:53:06 +0000 (20:53 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 15 Sep 2025 20:42:44 +0000 (22:42 +0200)
src/app/services/auth.service.ts

index dfd28581fe240e600a7df4ce8b65a936f973dfa6..3b4d86ae758566a3d9ac460377bd4bbd5e28b4c8 100644 (file)
@@ -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<string> {
+    const shouldFail = Math.random() < 0.3; // 30% Fehlerchance
+    if (shouldFail) {
+      return throwError(() => new Error('Simulierter Fehler im Service'));
+    }
+    this.username = username;
     return of(username);
   }