2

I am trying to get response message from jsonp error callback in angularjs, but response data is undefined. I return the response with 409 http code. If to open jsonp url directly in browser it shows "angular.callbacks._0({"message":"Reset link is incorrect"})", but I can't get this message in error callback. What am I doing wrong?

// Extend angular app for api requests
app.factory('User', function($http) {

    var User = function(data) {
        angular.extend(this, data);
    };

    // Send link for password reset to entered email
    User.reset_password = function() {
        return $http.jsonp(jsonp_url + 'user/reset_pass?_method=post&user_key=' + user_key + '&callback=JSON_CALLBACK');
    };

    return User;
});


app.controller('ResetPasswordController', function ResetPasswordController($scope, User){

    $scope.submit = function() {

        var response = User.reset_password();

        response.then(function(data){
            //Success callback
        }, function(data){
            // Error callback
            console.log(data) // Output: {config : {...}, data: undefined}
        });
    }

});
Vadim
  • 538
  • 2
  • 5
  • 23

1 Answers1

2

As said Brandon Tilley it is not possible to get data from jsonp response with http error code. If you want anyways to get error message you need to send something like this {result: false, msg: 'Error occured...'} with "good" http code, for example 200.

Vadim
  • 538
  • 2
  • 5
  • 23