Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle All Error From ReCaptchaV3Service #147

Closed
1 of 4 tasks
yanchespenda opened this issue Aug 11, 2019 · 4 comments
Closed
1 of 4 tasks

Handle All Error From ReCaptchaV3Service #147

yanchespenda opened this issue Aug 11, 2019 · 4 comments

Comments

@yanchespenda
Copy link

yanchespenda commented Aug 11, 2019

Summary

I'm submitting a:

  • bug report
  • feature request
  • question / support request
  • other

Description

When internet connection slow or something it will show Uncaught (in promise): [object Null] in console,
I was trying from using pipe errorCache before subscribe() still does not work
Screenshot (10)
Sometimes i get error same with #123 (comment)

A_LINK_WITH_YOUR_EXAMPLE
I'm used the code like this
https://stackblitz.com/edit/angular-t6kdki

Lib versions:

  • ng-recaptcha: 5.0.0
  • Angular: 8.2.0
  • Typescript (tsc --version): 3.5.3

Thank you for help!

@Smip
Copy link

Smip commented Jan 29, 2020

@yanchespenda Hi, how did you solve this problem?

@yanchespenda
Copy link
Author

yanchespenda commented Feb 1, 2020

@Smip I'm used timeout for cheking a error from the captcha

Like this,

recaptchaTimeout() {
    setTimeout(() => {
      if (this.isLoading && !this.isHttpLoading) {
        this.isLoading = false;
        this.errorMSG = 'Recaptcha Error, make sure your internet connection stable';
        this.isErrorPrimary = true;
      }
    }, 5500);
}

For submit form

SubmitA() {
    this.isErrorPrimary = false;
    this.isLoading = true;
    this.recaptchaTimeout();
    this.recaptchaUnsubscribe();
    this.recaptchaSubscriber = this.recaptchaV3Service.execute('login_a1')
      .subscribe((token) => {
        if (token === null) {
          // Response is null due to what? Expiration? reset?
          this.recaptchaUnsubscribe();
          return;
        }
        this.isHttpLoading = true;

        // Http services form
        ....
        // If http success
        this.isLoading= false;
   });
}

@Smip
Copy link

Smip commented Feb 2, 2020

@yanchespenda Thank you!

@Smip
Copy link

Smip commented Feb 2, 2020

More concise solution is:

SubmitA() {
  this.recaptchaV3Service.execute('login_a1')
      .pipe(
        timeoutWith(5000, throwError(new Error('timeout'))),
      )
      .subscribe(
        (token) => {
          // handle captcha token
        },
        (error) => {
          if (error.message === 'timeout') {
            // handle timeout
          }
        },
      );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants