Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Axios interceptors ordering
const axios = require('axios');
const a= axios.create()
a.interceptors.request.use(
(v) => (console.log('request 1 start'),v),
(v) => (console.log('request 1 end '),v)
)
a.interceptors.response.use(
(v) => (console.log('response 1 start'),v),
(v) => (console.log('response 1 end'),v)
)
a.interceptors.request.use(
(v) => (console.log('request 2 start'),v),
(v) => (console.log('request 2 end'),v)
)
a.interceptors.response.use(
(v) => (console.log('response 2 start'),v),
(v) => (console.log('response 2 end'),v)
)
// When run test
// request 2 start
// request 1 start
// response 1 end
// response 2 start
module.exports = a;
node # start repl mode
axois = require('./interceptors.js');
axois.get('/test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment