Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's worth remembering that:</p> <blockquote> <p>The ngResource module provides interaction support with RESTful services <a href="http://docs.angularjs.org/api/ngResource" rel="nofollow noreferrer">1</a></p> </blockquote> <p>When they say "RESTful services" they mean that they're making some assumptions about how your endpoint is going to behave. One of these assumptions is that the success or error status is going to be encoded by the HTTP Status Code.</p> <p>It sounds like you're trying to interact with a service that doesn't fit this pattern (i.e. you can have a failed request that returns <code>200: OK</code>). If that's the case you'd probably better off using <code>$http</code> directly, since it is more general:</p> <blockquote> <p>The $http service is a core Angular service that facilitates communication with the remote HTTP servers <a href="http://docs.angularjs.org/api/ng.$http" rel="nofollow noreferrer">2</a></p> </blockquote> <p>Since <code>$resource</code> is really just a wrapper around <code>$http</code> we can confirm the behaviour fairly easily by having a look at <a href="https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js#L461" rel="nofollow noreferrer">the source</a> (edited for clarity):</p> <pre><code>var promise = $http(httpConfig).then(function(response) { var data = response.data, promise = value.$promise; // snip value.$resolved = true; response.resource = value; return response; }, function(response) { value.$resolved = true; (error||noop)(response); return $q.reject(response); }); promise = promise.then( function(response) { var value = responseInterceptor(response); (success||noop)(value, response.headers); return value; }, responseErrorInterceptor); </code></pre> <p>Remember that <code>then()</code> takes a success and an error callback in that order. You can see that your interceptor is going to get called on success, along with the main success callback if there is one. </p> <p>It doesn't look like there's anything you can do inside your <code>responseInterceptor</code> that will cause the error callback to be executed.</p> <p>I think your options are:</p> <ul> <li>Modify the your server to behave in the way that <code>$resource</code> expects</li> <li>Roll your own version of <code>$resource</code> built on top of <code>$http</code> that works the way you want it to as suggested in <a href="https://stackoverflow.com/a/12805450/1344760">this answer</a>.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload