Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda