@@ -185,11 +185,12 @@ function shallowClearAndCopy(src, dst) {
185
185
* for more information.
186
186
* - **`responseType`** - `{string}` - see
187
187
* [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
188
- * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
189
- * `response` and `responseError`. Both `response` and `responseError` interceptors get called
190
- * with `http response` object. See {@link ng.$http $http interceptors}. In addition, the
191
- * resource instance or array object is accessible by the `resource` property of the
192
- * `http response` object.
188
+ * - **`interceptor`** - `{Object=}` - The interceptor object has four optional methods -
189
+ * `request`, `requestError`, `response`, and `responseError`. See
190
+ * {@link ng.$http $http interceptors} for details. Note that `request`/`requestError`
191
+ * interceptors are applied before calling `$http`, thus before any global `$http` interceptors.
192
+ * The resource instance or array object is accessible by the `resource` property of the
193
+ * `http response` object passed to response interceptors.
193
194
* Keep in mind that the associated promise will be resolved with the value returned by the
194
195
* response interceptor, if one is specified. The default response interceptor returns
195
196
* `response.resource` (i.e. the resource instance or array).
@@ -707,6 +708,9 @@ angular.module('ngResource', ['ng']).
707
708
var isInstanceCall = this instanceof Resource ;
708
709
var value = isInstanceCall ? data : ( action . isArray ? [ ] : new Resource ( data ) ) ;
709
710
var httpConfig = { } ;
711
+ var requestInterceptor = action . interceptor && action . interceptor . request || undefined ;
712
+ var requestErrorInterceptor = action . interceptor && action . interceptor . requestError ||
713
+ undefined ;
710
714
var responseInterceptor = action . interceptor && action . interceptor . response ||
711
715
defaultResponseInterceptor ;
712
716
var responseErrorInterceptor = action . interceptor && action . interceptor . responseError ||
@@ -743,7 +747,14 @@ angular.module('ngResource', ['ng']).
743
747
extend ( { } , extractParams ( data , action . params || { } ) , params ) ,
744
748
action . url ) ;
745
749
746
- var promise = $http ( httpConfig ) . then ( function ( response ) {
750
+ // Start the promise chain
751
+ var promise = $q .
752
+ resolve ( httpConfig ) .
753
+ then ( requestInterceptor ) .
754
+ catch ( requestErrorInterceptor ) .
755
+ then ( $http ) ;
756
+
757
+ promise = promise . then ( function ( response ) {
747
758
var data = response . data ;
748
759
749
760
if ( data ) {
0 commit comments