Created
September 16, 2019 07:31
-
-
Save retyui/82f7edcce12fbfa84250836ebe852855 to your computer and use it in GitHub Desktop.
Axios interceptors ordering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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