Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing interceptor chain when request interceptor is asynchronous #4013

Merged
merged 1 commit into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/Axios.js
Expand Up @@ -81,7 +81,7 @@ Axios.prototype.request = function request(config) {
var chain = [dispatchRequest, undefined];

Array.prototype.unshift.apply(chain, requestInterceptorChain);
chain.concat(responseInterceptorChain);
chain = chain.concat(responseInterceptorChain);

promise = Promise.resolve(config);
while (chain.length) {
Expand Down
29 changes: 29 additions & 0 deletions test/specs/interceptors.spec.js
Expand Up @@ -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) {
var response;

Expand Down