0

The return of the post is falling through the error callback yet the json I'm expecting is being returned by the api call. It is visible when I console.log the error object. I'll post the error log after the code.

The payload (userCreds) is json. Using postman, the api call returns as expected

Here's the post call:

    var deferred = $q.defer();

   $http.post(url, userCreds)
            .then(function(data, status) {
                $log.info('validateLogin status: ' + status)

                if(data){
                    requestor = data;
                }
                deferred.resolve(requestor);
            }, function (data, status) {
                var error =  data || "Request failed";
                $log.error('validateLogin error: ' + JSON.stringify(error));
                deferred.reject(error);
            });

     return deferred.promise;

The error object has the correct response in it with a 302 status. I noticed the transformRequest and transformResponse were null. I don't recall having to define these in the past. I thought angular automatically dealt with strings and javascript objects during transformations.

  {"data":{"$id":"1","innCodes":[],"userTypeId":0,"formId":0,"onqUserId":null,"fullName":"User Smith","firstName":"User","lastName":"Smith","phone":"214-555-4450","email":"user@email.com","userId":null,"password":null,"title":"Project Manager","fax":null,"mobile":null,"role":null},"status":302,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:25396/api/user/ValidateCredentials/","data":{"userName":"userid1234","password":"pwd123456"},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"Found"}
Will Lopez
  • 2,089
  • 3
  • 40
  • 64
  • I don't think there's enough info here to diagnose your issue. On an unrelated note, you are miusuing promises and would benefit from reading this http://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it – m59 Jul 18 '15 at 17:38
  • Thanks for the response @m59, I'll check that post out. What other info is needed? I have the call method and the response listed. The expected response object is visible in the "data" object - that is the json returned from the api call. – Will Lopez Jul 18 '15 at 17:59

1 Answers1

0

Ended up being the valid api response 302 (found) that was causing the quirky behavior. I was able to get the status code changed to 200 (OK) and now everything is working as expected. The 302 status was causing angular to reject the promise.

This line of code in angular v 1.2.26

  return (isSuccess(response.status))
      ? resp
      : $q.reject(resp);
Will Lopez
  • 2,089
  • 3
  • 40
  • 64