Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Method that causes infinite calls

I would just like to ask for suggestions and ideas about my current issue , I have a method which is getUserRoles which is fetching the logged-in user roles list.

The problem I have is that there are instances that the getUserGeneralDetails from the getUserRoles that is causing infinity , it is calling the getUserGeneralDetails infinitely and I dont understand why and what causes it.

Maybe somone can enlighten me with some problem with the code snippet I have below. Would be appreciatd, Thanks.

#method

  //In this method, we are just fetching the logged-in user roles list.
  public getUserRoles(): Promise<string[]> {

    if (this.authUser === null) {
      this.setAuthUser()
    }
    
    return new Promise((resolve, reject) => {
      this.userService
      .getUserGeneralDetails(this.authUser.nameid , this.accountId = 0)
        .pipe(catchError((error: any, caught: any) => {
          reject(error);
          return caught;
        }),
          map((res: any) => res.data && res.data.userAccountDto
            .filter(account => account.accountName === res.data.associatedAccount)
            .map(account => account.userRoleDto.roleName)
          )).subscribe((role: string[]) => {
            resolve(role);
          });

    });
  }

#code that calls the getUserRoles method

this.authService
          .loginWithCredentials(username, password)
          .then((r: any) => {
            localStorage.removeItem("previousUrl");
            if (r.isSuccess) {


              this.authService.getUserRoles().then((userRoles: string[]) => {
                localStorage.setItem("userRoles", JSON.stringify(userRoles));
              })

              
              this.route.navigateByUrl('/');
            }else{                                         
              if(r.errors.length > 0){                
                if(r.errors[0].description.indexOf('not found') !== -1){
                  errMsg = ERR_FORM_MSG.INVALID_LOGIN;
                }
              }
              this.apiErrMsg = errMsg;              
            }
          })
          .catch((e): any => {
            this.apiErrMsg = e.message
              ? e.message
              : errMsg;
          })
          .finally(() => {
            this.hasSubmit = false;
            this.closeLoader();
          });
      }

#user details

 getUserGeneralDetails(id: number , accountId:number): Observable<any> {
    const params = new HttpParams()
      .set('id', id.toString())
      .set('accountId', accountId.toString());
    return this.httpRequestService.get<any>(`${apiBaseUrl}/detail` , params);
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!