0

I have an interceptor that does if (response.status !== 200){ return $q.reject(response.statusText); }

Then in my $http I do

$http({
    method: 'POST',
    url: '/something/parameters',
    data: JSON.stringify(data)
  })
  .success(function(data, status, headers, config) {
    //
  })
  .error(handleError);

function handleError(data) {
  console.log(data) //undefined?!
}

I got undefined.

But when I do .error(function(data){ console.log(data) }) I got the response statusText, why? I have to split the function out because I have a service need to be triggered.

4
  • You're missing the "data" parameter in the $http call... Commented Nov 16, 2016 at 9:49
  • what should I do then? .error(handleError(data)); ? Commented Nov 16, 2016 at 9:51
  • tried, nope. @Vi100 it doesn't matter. Commented Nov 16, 2016 at 9:55
  • check response.data Commented Nov 16, 2016 at 10:23

1 Answer 1

1

Well, several things:

1) You are not providing the data parameter in your POST call. If you're not going to post anything, just use a get, or at least remove the ',' after the url parameter...

2) The structure you're using to make the $http call is DEPRECATED and is going to be removed in Angular 1.6 when it goes out from beta. Use this signature instead:

$http({
  method: 'POST',
  url: '/someUrl',
  data: hereTheDataYouWantToPost
}).then(function successCallback(response) {
    // this callback will be called asynchronously when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs or server returns response with an error status.
    console.log(response.data);
  });

3) The response data is now attached to de response parameter... (that is: response.data) inside the callbacks.

See Angular $http for a complete reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.