mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Correctly add response interceptors to interceptor chain (#4013)
This commit is contained in:
+1
-1
@@ -81,7 +81,7 @@ Axios.prototype.request = function request(config) {
|
|||||||
var chain = [dispatchRequest, undefined];
|
var chain = [dispatchRequest, undefined];
|
||||||
|
|
||||||
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
||||||
chain.concat(responseInterceptorChain);
|
chain = chain.concat(responseInterceptorChain);
|
||||||
|
|
||||||
promise = Promise.resolve(config);
|
promise = Promise.resolve(config);
|
||||||
while (chain.length) {
|
while (chain.length) {
|
||||||
|
|||||||
@@ -252,6 +252,35 @@ describe('interceptors', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add a response interceptor when request interceptor is defined', function (done) {
|
||||||
|
var response;
|
||||||
|
|
||||||
|
axios.interceptors.request.use(function (data) {
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
axios.interceptors.response.use(function (data) {
|
||||||
|
data.data = data.data + ' - modified by interceptor';
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
axios('/foo').then(function (data) {
|
||||||
|
response = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
getAjaxRequest().then(function (request) {
|
||||||
|
request.respondWith({
|
||||||
|
status: 200,
|
||||||
|
responseText: 'OK'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
expect(response.data).toBe('OK - modified by interceptor');
|
||||||
|
done();
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should add a response interceptor that returns a new data object', function (done) {
|
it('should add a response interceptor that returns a new data object', function (done) {
|
||||||
var response;
|
var response;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user