title: Handle error codes (401, 403) with Restangular
body: <p>I am building an app using Restangular. I would implement in one place handling of errors like 401, 403, 500 etc in a response interceptor.</p>
  
  <p>This is what I wrote:</p>
  
  <pre><code>RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
    switch(response.meta.code) {
      case 200:
        // Handle 200
      break;
  
      case 401:
        // Redirect to login
      break;
  
      /* ... */
  
      default:
      break;
    }
  }
  </code></pre>
  
  <p>What actually happens it's that the 200 is correctly <em>seen</em> but this method is not hit at all for the 401. 
  The JSON I get from server side it is formatted like this for successful responses:</p>
  
  <pre><code>{"meta":{"apiVersion":"0.1","code":200,"errors":null},"response":{"response":"value"}}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>{"meta":{"apiVersion":"0.1","code":401,"errors":[{"code":401,"message":"Unauthorized"}]},"response":null}
  </code></pre>
  
  <p>for errors. The response header contains the <code>Status Code:401 Unauthorized</code> as well.
  What am I doing wrong?</p>