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

289
Vistas
Why am I going into .then() when I'm rejecting the promise in Angular 1?

I have a function that check if the id is <=0 and rejects the promise if it is, otherwise it find an assessment and resolves the promise with an assessment. My problem is that right now when I pass -1 to the function it goes into the .then anyway, even though I expect it not to, which causes problems. I don't quite understand why is this happening.

    AssessmentsService.getClientAssessment($scope.graphAssessment.id)
      .then((assessment) => {
        if ($scope.clientAssessments) {
          $scope.clientAssessments.title.text = 'All Time ' + assessment.shortName;
        }
        if ($scope.thirtyDayAssessments) {
          $scope.thirtyDayAssessments.title.text = '30 Day ' + assessment.shortName;
        }
      })
      .catch((error) => {
        console.log(error);
      });

This is the getClientAssessment function:

  getClientAssessment(id, forceRefresh) {
    if (id <= 0) {
      return this.$q.reject();
    }

    const assessmentId = Number(id);
    const assessment = _.find(this.assessments, (a) => a.id === assessmentId);

    if (!assessment || forceRefresh) {
      return this.authHttp
        .get(`${this.Environment.serverURL}/assessments/${id}`)
        .then(({ data }) => {
          this.assessments.push(data);
          return data;
        })
        .catch((error) => {
          console.error(error);
        });
    }

    return this.$q.resolve(assessment);
  }
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