how to catch exceptions if any exception occurs in $http call

how to catch exceptions if any exception occurs in http call(at server-side)?first of all Is it correct way to send http post request?what is the difference between then and success in http post request.

var search = angular.module('search', []);

   var req = {"field": 1};

 hboSearchApp.factory('productFactory', function($http,$q){
                      var defer = $q.defer();
                                return {
                                                getResponse : function () {
                                                      return defer.promise;
            }).controller('productsCtrl', function($http,$scope, productFactory) {
                //This will be called when the page loads
                var promise= productFactory.getResponse();
                  $scope.productList =;
});//end of productsCtrl
LVL 20
chaitu chaituAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First "success" is a deprecated method of the $http service and should be replaced by "then"$http

Secondly the way you want to defer and catch errors is nicely explained by, look particularly at the last boxed bit of code headed with "Here's one such possible solution" and the comment by Tomas Lycken.

Personally I use the $http service directly, having no need to defer things, with .success and .error for the cases when I want to report an error, and .then when I silently ignore them. But I'll have to change  in the future.$http

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.