Skip to content

Commit d797954

Browse files
committed
display errors when updating user pwd does not work
1 parent 29b5d02 commit d797954

File tree

4 files changed

+13
-34
lines changed

4 files changed

+13
-34
lines changed

src/@seed/api/user/user.service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { HttpErrorResponse } from '@angular/common/http'
22
import { HttpClient } from '@angular/common/http'
33
import { inject, Injectable } from '@angular/core'
44
import type { Observable } from 'rxjs'
5-
import { catchError, distinctUntilChanged, ReplaySubject, switchMap, take, tap } from 'rxjs'
5+
import { catchError, distinctUntilChanged, ReplaySubject, switchMap, take, tap, throwError } from 'rxjs'
66
import type {
77
CurrentUser,
88
GenerateApiKeyResponse,
@@ -78,7 +78,9 @@ export class UserService {
7878
tap(() => {
7979
this.getCurrentUser().subscribe()
8080
}),
81-
// todo: how do I catch errors?
81+
catchError((error: HttpErrorResponse) => {
82+
return throwError(() => error)
83+
}),
8284
)
8385
}
8486

src/app/core/auth/auth.interceptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn):
3232
})
3333

3434
return next(newReq).pipe(
35-
catchError(() => {
36-
return throwError(() => new Error(`Failed request ${req.method} ${req.url}`))
35+
catchError((error: HttpErrorResponse) => {
36+
return throwError(() => error)
3737
}),
3838
)
3939
} else {

src/app/modules/profile/security/security.component.html

+3-22
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,15 @@ <h1 class="mb-6 flex items-center text-center text-2xl"><mat-icon class="mr-2" s
77
<mat-form-field class="gt-xs:pr-3 flex-auto">
88
<mat-label>{{ t('Current Password') }} </mat-label>
99
<input [formControlName]="'currentPassword'" type="password" matInput [type]="hide() ? 'password' : 'text'" />
10-
<button
11-
mat-icon-button
12-
matSuffix
13-
(click)="clickEvent($event)"
14-
[attr.aria-label]="'Hide password'"
15-
[attr.aria-pressed]="hide()"
16-
>
10+
<button mat-icon-button matSuffix (click)="clickEvent($event)" [attr.aria-label]="'Hide password'" [attr.aria-pressed]="hide()">
1711
<mat-icon class="icon-size-5" [svgIcon]="hide() ? 'fa-solid:eye-slash' : 'fa-solid:eye'"></mat-icon>
1812
</button>
1913
</mat-form-field>
2014

21-
2215
<mat-form-field class="gt-xs:pl-3 mb-6 flex-auto">
2316
<mat-label>{{ t('New Password') }}</mat-label>
2417
<input [formControlName]="'newPassword'" type="password" matInput [type]="hide() ? 'password' : 'text'" />
25-
<button
26-
mat-icon-button
27-
matSuffix
28-
(click)="clickEvent($event)"
29-
[attr.aria-label]="'Hide password'"
30-
[attr.aria-pressed]="hide()"
31-
>
18+
<button mat-icon-button matSuffix (click)="clickEvent($event)" [attr.aria-label]="'Hide password'" [attr.aria-pressed]="hide()">
3219
<mat-icon class="icon-size-5" [svgIcon]="hide() ? 'fa-solid:eye-slash' : 'fa-solid:eye'"></mat-icon>
3320
</button>
3421
<mat-hint>{{
@@ -45,13 +32,7 @@ <h1 class="mb-6 flex items-center text-center text-2xl"><mat-icon class="mr-2" s
4532
<mat-form-field class="flex-auto">
4633
<mat-label>{{ t('Confirm New Password') }}</mat-label>
4734
<input [formControlName]="'confirmNewPassword'" type="password" matInput [type]="hide() ? 'password' : 'text'" />
48-
<button
49-
mat-icon-button
50-
matSuffix
51-
(click)="clickEvent($event)"
52-
[attr.aria-label]="'Hide password'"
53-
[attr.aria-pressed]="hide()"
54-
>
35+
<button mat-icon-button matSuffix (click)="clickEvent($event)" [attr.aria-label]="'Hide password'" [attr.aria-pressed]="hide()">
5536
<mat-icon class="icon-size-5" [svgIcon]="hide() ? 'fa-solid:eye-slash' : 'fa-solid:eye'"></mat-icon>
5637
</button>
5738
<!-- this isn't working reliably -->

src/app/modules/profile/security/security.component.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { SharedImports } from '@seed/directives'
1616
selector: 'seed-profile-security',
1717
templateUrl: './security.component.html',
1818
encapsulation: ViewEncapsulation.None,
19-
changeDetection: ChangeDetectionStrategy.OnPush,
19+
changeDetection: ChangeDetectionStrategy.Default,
2020
imports: [
2121
AlertComponent,
2222
MatIconModule,
@@ -70,19 +70,18 @@ export class ProfileSecurityComponent implements OnInit, OnDestroy {
7070
onSubmit() {
7171
// Handle form submission
7272
if (this.passwordForm.valid) {
73-
console.log('VALID')
7473
const passwordData = {
7574
current_password: this.passwordForm.value.currentPassword,
7675
password_1: this.passwordForm.value.newPassword,
7776
password_2: this.passwordForm.value.confirmNewPassword,
7877
} as PasswordUpdateRequest
7978

8079
this._userService.updatePassword(passwordData).subscribe({
81-
error: (error) => {
82-
console.error('Error:', error)
80+
error: (error: { error?: { message?: string } }) => {
81+
const error_msg = error.error?.message || 'An unknown error occurred.'
8382
this.alert = {
8483
type: 'error',
85-
message: 'Update User Unsuccessful...',
84+
message: `Error Updating Password: ${error_msg}`,
8685
}
8786
this.showAlert = true
8887
},
@@ -94,9 +93,6 @@ export class ProfileSecurityComponent implements OnInit, OnDestroy {
9493
this.showAlert = true
9594
},
9695
})
97-
} else {
98-
console.log('NOT VALID')
99-
// TODO: handle
10096
}
10197
}
10298

0 commit comments

Comments
 (0)