title: Catching errors in AngularJS when using $resource
body: <p>Searching product is working fine when product is found, but if user search with letters, or bad criteria, nothing happens. I can see the error message in JavaScript-console and in Header there is Status Code 204, no Content. I think that Angular is just working badly, when empty object is coming back. How can I tell an user that there is no products with his/her criteria, cause I can't catch the error message at all at the moment. What is the correct and best solution to handle this? Catching errors or solving that result was empty and showing an error message in HTML-page?</p>
  
  <h3>Service:</h3>
  
  <pre><code>return $resource(
  
                      'http://localhost:8080/RMAServer/webresources/com.rako.entity.jdeserials/:id',
                      {},
                      {
                          get: { method: 'GET',isArray:false, params: {id: '@serial'} },
                          update: { method: 'PUT', params: {id: '@serial'} }
                      });
  </code></pre>
  
  <h3>Controller</h3>
  
  <pre><code>    //Searching product with serial number/LOTN
                  $scope.searchProduct = function () {
                      $scope.serials = lotnSvc.get({id: $scope.serial}).$promise.then(
                          function (data) {
                              var litm = data.litm;
  
                              productSvc.get({id: litm}, function (product) {
                              $scope.product = product;
                              getBrands();
                          },function(error){
                        alert('ERROR when searching product'); 
                        console.log("error----&gt;" + error);
                      });
                      },function(error){
                        alert('ERROR when searching product'); 
                        console.log("error----&gt;" + error); 
                      });
  
                  };
  </code></pre>
  
  <h3>Error message in javaScript console</h3>
  
  <pre><code>Error: [$resource:badcfg] Error in resource configuration for action `get`. Expected response to contain an object but got an array
  http://errors.angularjs.org/1.3.15/$resource/badcfg?p0=get&amp;p1=object&amp;p2=array
  at REGEX_STRING_REGEXP 
  </code></pre>
  
  <p><strong>Status code in Header</strong></p>
  
  <p><img src="https://i.stack.imgur.com/7CPOf.png" alt="Status code in header after GET"></p>