Skip to content

Commit 83ae383

Browse files
author
Julian Hollmann
authored
Correctly add response interceptors to interceptor chain (#4013)
1 parent c0c8761 commit 83ae383

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

lib/core/Axios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Axios.prototype.request = function request(config) {
8181
var chain = [dispatchRequest, undefined];
8282

8383
Array.prototype.unshift.apply(chain, requestInterceptorChain);
84-
chain.concat(responseInterceptorChain);
84+
chain = chain.concat(responseInterceptorChain);
8585

8686
promise = Promise.resolve(config);
8787
while (chain.length) {

test/specs/interceptors.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,35 @@ describe('interceptors', function () {
252252
});
253253
});
254254

255+
it('should add a response interceptor when request interceptor is defined', function (done) {
256+
var response;
257+
258+
axios.interceptors.request.use(function (data) {
259+
return data;
260+
});
261+
262+
axios.interceptors.response.use(function (data) {
263+
data.data = data.data + ' - modified by interceptor';
264+
return data;
265+
});
266+
267+
axios('/foo').then(function (data) {
268+
response = data;
269+
});
270+
271+
getAjaxRequest().then(function (request) {
272+
request.respondWith({
273+
status: 200,
274+
responseText: 'OK'
275+
});
276+
277+
setTimeout(function () {
278+
expect(response.data).toBe('OK - modified by interceptor');
279+
done();
280+
}, 100);
281+
});
282+
});
283+
255284
it('should add a response interceptor that returns a new data object', function (done) {
256285
var response;
257286

0 commit comments

Comments
 (0)