Skip to content

Instantly share code, notes, and snippets.

@retyui
Created September 16, 2019 07:31
Show Gist options
  • Save retyui/82f7edcce12fbfa84250836ebe852855 to your computer and use it in GitHub Desktop.
Save retyui/82f7edcce12fbfa84250836ebe852855 to your computer and use it in GitHub Desktop.
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