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

292
Visualizações
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 à 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