Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/app/auth/auth.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/app/auth/auth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions src/app/core/_services/access/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading