0

When using angular's $http.head(), it returns a status. When the item does not exist, I get a 404 error in my console.

How do I catch this error and take action when the status is 200 and take no action otherwise?

3
  • are you using .then to resolve the promise $http.head('/someUrl', config).then(successCallback, errorCallback); Commented Aug 9, 2016 at 13:46
  • Yes I am using .then(data=>{},err=>{}) Commented Aug 9, 2016 at 14:28
  • If my answer sufficiently answered your question can you please mark it as the answer to this question. Commented Aug 9, 2016 at 15:24

1 Answer 1

1

This should give the functionality you are looking for:

var successCallback = function(response) {
 //do your stuff when successful (status 200)

}

var errorCallback = function(response) {
 //do your stuff when there is an error (400, 404 ect..)

} 
$http.head('/someUrl', config).then(successCallback, errorCallback);

As far as suppressing the error itself from showing up in your console, I believe that is just a browser functionality.

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.