How to get data from JSONP error callback in angularjs?

I am trying to get a response message from jsonp error callback in angularjs, but the response data is undefined. I am returning a response with a 409 http code. If you open the jsonp url directly in the browser, it displays "angular.callbacks._0 ({" message ":" Reset link is incorrect "})", but I can not get this message in the 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} }); } }); 
+1
source share
1 answer

As Brandon Tilly said, it's not possible to get data from a jsonp response with an http error code. If you want to receive an error message, you need to send something like this {result: false, msg: "An error occurred ..."} with a "good" http code, for example 200.

+2
source

Source: https://habr.com/ru/post/1495994/


All Articles