Skip to content

Commit

Permalink
Merge pull request #1324 from thebiggive/DON-901-person-update-retry
Browse files Browse the repository at this point in the history
DON-901 – retry ID service updates on failure
  • Loading branch information
NoelLH authored Oct 3, 2023
2 parents cfc504a + b3814ca commit 8f36d6e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
78 changes: 40 additions & 38 deletions src/app/donation-complete/donation-complete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,35 @@ export class DonationCompleteComponent implements OnInit {
}

this.person.raw_password = password;
this.identityService.update(this.person)
.subscribe(
() => { // Success. Must subscribe for call to fire.
this.registerError = undefined;
this.registrationComplete = true;
this.matomoTracker.trackEvent('identity', 'person_password_set', 'Account password creation complete');

// We should only auto-login (and therefore execute the captcha) if the donor requested a persistent session.
if (stayLoggedIn) {
this.captcha.execute(); // Leads to loginCaptchaReturn() assuming the captcha succeeds.
} else {
// Otherwise we should remove even the temporary ID token.
this.identityService.clearJWT();
}
},
(error: HttpErrorResponse) => {
const htmlErrorDescription = error.error?.error?.htmlDescription;
if (error.error?.error?.type === "DUPLICATE_EMAIL_ADDRESS_WITH_PASSWORD") {
this.registerErrorDescription = "Your password could not be set. There is already a password set for your email address.";
} else if (htmlErrorDescription) {
// we bypass security because we trust the Identity server.
this.registerErrorDescriptionHtml = this.sanitizer.bypassSecurityTrustHtml(htmlErrorDescription)
} else {
this.registerErrorDescription = error.error?.error?.description
}

this.registerError = error.message;
this.matomoTracker.trackEvent('identity_error', 'person_password_set_failed', `${error.status}: ${error.message}`);
},
);
this.identityService.update(this.person).subscribe({
next: () => { // Success. Must subscribe for call to fire.
this.registerError = undefined;
this.registrationComplete = true;
this.matomoTracker.trackEvent('identity', 'person_password_set', 'Account password creation complete');

// We should only auto-login (and therefore execute the captcha) if the donor requested a persistent session.
if (stayLoggedIn) {
this.captcha.execute(); // Leads to loginCaptchaReturn() assuming the captcha succeeds.
} else {
// Otherwise we should remove even the temporary ID token.
this.identityService.clearJWT();
}
},
error: (error: HttpErrorResponse) => {
const htmlErrorDescription = error.error?.error?.htmlDescription;
if (error.error?.error?.type === "DUPLICATE_EMAIL_ADDRESS_WITH_PASSWORD") {
this.registerErrorDescription = "Your password could not be set. There is already a password set for your email address.";
} else if (htmlErrorDescription) {
// we bypass security because we trust the Identity server.
this.registerErrorDescriptionHtml = this.sanitizer.bypassSecurityTrustHtml(htmlErrorDescription)
} else {
this.registerErrorDescription = error.error?.error?.description
}

this.registerError = error.message;
this.matomoTracker.trackEvent('identity_error', 'person_password_set_failed', `${error.status}: ${error.message}`);
},
});
}

private setDonation(donation: Donation) {
Expand All @@ -202,14 +201,17 @@ export class DonationCompleteComponent implements OnInit {
this.registrationComplete = true;
} else {
this.identityService.update(person)
.subscribe(person => {
this.patchedCorePersonInfo = true;
this.person = person;
this.offerToSetPassword = !person.has_password;
}, (error: HttpErrorResponse) => {
// For now we probably don't really need to inform donors if we didn't patch their Person data, and just won't ask them to
// set a password if the first step failed. We'll want to monitor Analytics for any patterns suggesting a problem in the logic though.
this.matomoTracker.trackEvent('identity_error', 'person_core_data_update_failed', `${error.status}: ${error.message}`);
.subscribe({
next: person => {
this.patchedCorePersonInfo = true;
this.person = person;
this.offerToSetPassword = !person.has_password;
},
error: (error: HttpErrorResponse) => {
// For now we probably don't really need to inform donors if we didn't patch their Person data, and just won't ask them to
// set a password if the first step failed. We'll want to monitor Analytics for any patterns suggesting a problem in the logic though.
this.matomoTracker.trackEvent('identity_error', 'person_core_data_update_failed', `${error.status}: ${error.message}`);
},
});
} // End token-not-finalised condition.
} // Else no ID JWT saved. Donor may have already set a password but opted to log out.
Expand Down
5 changes: 3 additions & 2 deletions src/app/identity.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Inject, Injectable, InjectionToken} from '@angular/core';
import jwtDecode from 'jwt-decode';
import {CookieService} from 'ngx-cookie-service';
import {MatomoTracker} from 'ngx-matomo';
import {StorageService} from 'ngx-webstorage-service';
import {Observable, of} from 'rxjs';
import {delay, retry} from 'rxjs/operators';

import {Credentials} from './credentials.model';
import {environment} from '../environments/environment';
import {IdentityJWT} from './identity-jwt.model';
import {Person} from './person.model';
import {FundingInstruction} from './fundingInstruction.model';
import {CookieService} from 'ngx-cookie-service';

export const TBG_DONATE_ID_STORAGE = new InjectionToken<StorageService>('TBG_DONATE_ID_STORAGE');

Expand Down Expand Up @@ -109,7 +110,7 @@ export class IdentityService {
`${environment.identityApiPrefix}${this.peoplePath}/${person.id}`,
person,
this.getAuthHttpOptions(person),
);
).pipe(retry(2), delay(2_000));
}

clearJWT() {
Expand Down

0 comments on commit 8f36d6e

Please sign in to comment.