尽管状态码201,角度后触发器捕获

时间:2017-11-26 15:44:21

标签: angularjs

我已经创建了一个服务来处理带有两个回调的signUp。但是,即使statusCode为201并且成功,它仍然似乎在error的控制台中记录console.log('error')。我想知道当我查看我的代码时如何发生这种情况我在errorCallback中呼叫catch

服务

(function () {
    'use strict';

    angular
    .module('KryptoApp')
    .factory('Authentication', Authentication);

    Authentication.$inject = ['$cookies', '$http'];

    function Authentication($cookies, $http) {

    var Authentication = {
        register: register
    };

    return Authentication;
    function register(email, password, username, successCallback, errorCallback) {
        return $http.post('/api/v1/accounts/', {
        username: username,
        password: password,
        email: email
        })
        .then(successCallback)
        .catch(errorCallback)
    }
    function login(email, password) {
        return $http.post('/api/v1/auth/login/', {
        email: email, password: password
        });
    }
    }
})();

控制器

   Authentication.register(vm.email, vm.password, vm.username, function(result){
      // Success callback
      $timeout(function(){
        vm.success = true;
        vm.loading = false;
      }, 2000);
      console.log('success');
    }, function(result){
      // Error callback
      console.log('error');
      var response = result.data
      vm.error = true;
      if (response.email != undefined) {
        vm.error_msg = response.email[0];
      } else {
        vm.error_msg = 'Uventet fejl. prøv igen senere!'
      }

      vm.loading = false;
    });

0 个答案:

没有答案