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

284
Views
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
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!