title: Handling 406 http response in angularjs
body: <p>I'm using angular with an ngResource factory with a restful controller on a Rails backend. My API responds with a  406 response with a json response structured like the following when a post request is made to create a new record:</p>
  
  <pre><code>{ success: false, errors ['error1', 'error2'], message: "record didn't save" }
  </code></pre>
  
  <p>The problem is that I see a post request error in my console when I return the 406 response from the API and angular fails to handle the response. </p>
  
  <p>Something like:</p>
  
  <pre><code>POST http://localhost:3000/api/widget/384/comments 406 (Not Acceptable)    includes.js?v=e777c6e0fdfb9a725e857c8ca3eab18f:545
    sendReplacement includes.js?v=e777c6e0fdfb9a725e857c8ca3eab18f:545
    (anonymous function) angular.js?body=1:8381
    sendReq angular.js?body=1:8181
    $http.serverRequest angular.js?body=1:7922
    wrappedCallback angular.js?body=1:11320
    wrappedCallback angular.js?body=1:11320
    (anonymous function) angular.js?body=1:11406
    Scope.$eval angular.js?body=1:12413
    Scope.$digest angular.js?body=1:12225
    Scope.$apply angular.js?body=1:12517
    (anonymous function) angular.js?body=1:18627
    jQuery.event.dispatch jquery.js?body=1:5117
    elemData.handle
  </code></pre>
  
  <p>My angular code is structured like:</p>
  
  <pre><code>Object.save( { object_id: 1 } ).$promise.then(function (response) {
    if (response.success) {
      //success
    } else {
      // something else
    }
  </code></pre>
  
  <p>How do I instruct angular to handle this kind of HTTP response?</p>