Skip to content

Commit

Permalink
fix(component): handle top-level execute errors for reCAPTCHA v3
Browse files Browse the repository at this point in the history
closes #194
  • Loading branch information
Ruslan Arkhipau authored and Ruslan Arkhipau committed Dec 1, 2020
1 parent 80c9e6e commit c7d02ce
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions recaptcha/recaptcha-v3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,34 @@ export class ReCaptchaV3Service {

/** @internal */
private executeActionWithSubject(action: string, subject: Subject<string>): void {
this.zone.runOutsideAngular(() => {
// tslint:disable-next-line:no-any
(this.grecaptcha.execute as any)(
this.siteKey,
{ action },
).then((token: string) => {
this.zone.run(() => {
subject.next(token);
subject.complete();
if (this.onExecuteSubject) {
this.onExecuteSubject.next({ action, token });
}
});
// tslint:disable-next-line:no-any
}, (error: any) => {
this.zone.run(() => {
subject.error(error);
if (this.onExecuteErrorSubject) {
this.onExecuteErrorSubject.next({ action, error });
}
});
// tslint:disable-next-line:no-any
const onError = (error: any) => {
this.zone.run(() => {
subject.error(error);
if (this.onExecuteErrorSubject) {
this.onExecuteErrorSubject.next({ action, error });
}
});
};

this.zone.runOutsideAngular(() => {
try {
// tslint:disable-next-line:no-any
(this.grecaptcha.execute as any)(
this.siteKey,
{ action },
).then((token: string) => {
this.zone.run(() => {
subject.next(token);
subject.complete();
if (this.onExecuteSubject) {
this.onExecuteSubject.next({ action, token });
}
});
}, onError);
} catch (e) {
onError(e);
}
});
}

Expand Down

0 comments on commit c7d02ce

Please sign in to comment.