Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda