Home > Net >  Angular Http Interceptor - fromPromise error - TypeError: (0 , x.fromPromise) is not a function
Angular Http Interceptor - fromPromise error - TypeError: (0 , x.fromPromise) is not a function

Time:10-18

I am use the function below to attach recaptcha v3 to Http Request.

@Injectable()
export class RecaptchaInterceptor implements HttpInterceptor {
constructor(private recaptchaService: ReCaptchaService) { }

intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {    
  return fromPromise(this.recaptchaService.execute({ action: 'login' }))
    .pipe(switchMap(token => {
      const headers = httpRequest.headers
        .set('recaptcha', token)
      const reqClone = httpRequest.clone({
        headers
      });
      return next.handle(reqClone);
    }));
}

In localhost this is work fine, But from some reason after publish i am getting the following error:

Uncaught (in promise): TypeError: (0 , x.fromPromise) is not a function TypeError: (0 , x.fromPromise) is not a function

Any suggestions? Thanks a lot!

CodePudding user response:

You can use from instead of fromPromise because i think you are using rxjs 6

import { from } from 'rxjs';

...
return from(this.recaptchaService.execute({ action: 'login' }))
  • Related