title: JS/Ionic:TypeError: Cannot read property 'code' of undefined
body: <p>I am just a beginner in JS. I am trying to log in from the db using php RESTful web service. If the login credentials match the user is shown the home page.
  The error I am getting is: TypeError: Cannot read property 'code' of undefined at services.js:65
  What should I do to solve this error? And why did this error happen?</p>
  
  <p>My services.js is:</p>
  
  <pre><code>.service('LoginService', function ($q, $http) {
  return {
      loginUser: function (loginData) {
          var deferred = $q.defer(),
              promise = deferred.promise;
  
          $http({
              url: 'http://localhost/login.php',
              method: "POST",
              data: loginData,
              headers: {'Content-Type': 'application/json'}
          })
              .then(function (response) {
                  if (response.data.error.code === "000") {
                      console.log("User login successful: " + JSON.stringify(response.data));
                      deferred.resolve(response.data);
                  } else {
                      console.log("User login failed: " + JSON.stringify(response.data.error));
                      deferred.reject(response.data);
                  }
              }, function (error) {
                  console.log("Server error on Login " + JSON.stringify(error));
                  deferred.reject(error);
              });
  
          promise.success = function (fn) {
              promise.then(fn);
              return promise;
          };
          promise.error = function (fn) {
              promise.then(null, fn);
              return promise;
          };
          return promise;
      }
    };
  });
  </code></pre>