title: TypeError: Cannot read property 'success' of undefined using $http
body: <p>i'm creating a service for http communication, i need some way to return a value..
  But I get a Type Error , when I call success ;( ..</p>
  
  <p><strong>"TypeError: Cannot read property 'success' of undefined"</strong></p>
  
  <pre><code>angular.module('myApp').controller('mainCtrl', function($scope, apiService){    
    $scope.GetJson = function() {
      apiService('post','http://myApiAddress', "{'dataFn': 'userInfo'}")
      .success(function(response) { // ERROR !!! TypeError: Cannot read property 'success' of undefined
        $scope.userinfo = response;
      })
      .error(function(error){
        console.log(error);
      })
    }
  
  })
  
  ---------------------------------------------------------------------------
  
  var module = angular.module('httpService',[]);
  module.factory('apiService',['$http',function($http){
  
   var userAuthority = true; // or false (boolean Value)
  
   var apiService = function (method, url, param){
      if(userAuthority){
        apiService.idCheck().success( function(res) {
          return $http[method](url, param);
        })
        .error( function(err) {
            console.log(err);
        })
      }
      else {
        return $http[method](url, param);
      }
    };
    apiService.idCheck = function () {
      return $http.get('http://myApiAddress');
    };
  }])
  </code></pre>
  
  <p>I'm looking for one of two answers:</p>
  
  <ol>
  <li>Why is the success callback returning an error?</li>
  <li>How can I fix this error ?</li>
  </ol>