title: TypeError: Cannot read property 'protocol' of undefined
body: <p>I cannot understand why my factory for communication with REST API doesn't work. 
  I receive the following errors:</p>
  
  <pre><code>TypeError: Cannot read property 'protocol' of undefined
  </code></pre>
  
  <p>and</p>
  
  <pre><code>TypeError: Cannot read property 'message' of undefined
  </code></pre>
  
  <p><strong>todo.controller.js</strong></p>
  
  <pre><code>'use strict';
  angular
      .module('app')
      .controller('TodoController', ['$scope', 'todoFactory', function ($scope, todoFactory) {
  
          getTodos();
  
          function getTodos() {
              todoFactory.all()
                  .success(function (todos) {
                      $scope.todos = todos;
                  })
                  .error(function (error) {
                      $scope.status = 'Unable to load todo data: ' + error.message;
                  });
          }
  
      }]);
  </code></pre>
  
  <p><strong>todo.factory.js</strong></p>
  
  <pre><code>'use strict';
  angular.module('app')
      .constant('API_URI', 'http://localhost:8080/api/todo')
      .factory('todoFactory', ['$http', function($http, API_URI) {
  
          var todoFactory = {};
  
          function getUrl() {
              return API_URI;
          }
  
          function getUrlForId(itemId) {
              return getUrl + itemId;
          }
  
          todoFactory.all = function () {
              return $http.get(getUrl());
          };
  
          todoFactory.fetch = function (id) {
              return $http.get(getUrlForId(id));
          };
  
          todoFactory.add = function (todo) {
              return $http.post(getUrl(), todo);
          };
  
          todoFactory.update = function (todo) {
              return $http.put(getUrlForId(id), todo)
          };
  
          todoFactory.delete = function (id) {
              return $http.delete(getUrlForId(id));
          };
  
          return todoFactory;
      }]);
  </code></pre>
  
  <p>However, if I will invoke simple $http.get(something) in the controller that works:</p>
  
  <pre><code>   $http.get('http://localhost:8080/api/todo').
          success(function(data) {
              $scope.todos = data;
          });
  </code></pre>
  
  <p>What I do wrong with my factory usage in comparison with simple direct $http.get() in controller?</p>