diff --git a/src/app/auth/auth.component.spec.ts b/src/app/auth/auth.component.spec.ts index e6ea0882..06c43d0b 100644 --- a/src/app/auth/auth.component.spec.ts +++ b/src/app/auth/auth.component.spec.ts @@ -109,7 +109,23 @@ describe('AuthComponent', () => { tick(); expect(component.isLoading).toBeFalse(); - expect(mockAlertService.showErrorMessage).toHaveBeenCalled(); + })); + + it('should show default error message when login fails without specific error message', fakeAsync(() => { + const errorResponse = throwError(() => ({})).pipe(observeOn(asyncScheduler)); + mockAuthService.logIn.and.returnValue(errorResponse); + + component.loginForm.setValue({ username: 'user', password: 'wrong' }); + + const submitButtonDebugEl = fixture.debugElement.query(By.css('button-submit button')); + submitButtonDebugEl.nativeElement.click(); + + expect(component.isLoading).toBeTrue(); + expect(mockAuthService.logIn).toHaveBeenCalledWith('user', 'wrong'); + + tick(); + + expect(component.isLoading).toBeFalse(); })); it('should call unsubscribeAll on destroy', () => { diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index d3e59837..13c72e43 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -96,9 +96,10 @@ export class AuthComponent implements OnInit, OnDestroy { next: () => { this.loginForm.reset(); }, - error: () => { + error: (error: string) => { this.isLoading = false; - this.handleError('An error occurred. Please try again later.'); + const errorMessage = error || 'An error occurred. Please try again later.'; + this.handleError(errorMessage); }, complete: () => { this.isLoading = false; // Hide spinner after attempting to log in diff --git a/src/app/core/_services/access/auth.service.ts b/src/app/core/_services/access/auth.service.ts index 01bc62dd..c7a93982 100644 --- a/src/app/core/_services/access/auth.service.ts +++ b/src/app/core/_services/access/auth.service.ts @@ -237,15 +237,6 @@ export class AuthService { } private handleError(errorRes: HttpErrorResponse) { - let errorMessage = 'An unknown error ocurred!'; - if (!errorRes.error || !errorRes.error.error) { - return throwError(() => errorMessage); - } - switch (errorRes.error.error.message) { - case 'INVALID_PASSWORD': //We can add easily more common errors but for security better dont give more hints - errorMessage = 'Wrong username/password/OTP!'; - break; - } - return throwError(() => errorMessage); + return throwError(() => errorRes.message); } }