File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ export default class Axios {
55 this . instance = http . axios || axios . create ( http ) ;
66 this . setAuthentication ( http . access_token ) ;
77
8+ this . instance . interceptors . request . use (
9+ config => http . onRequest ( config , this . instance ) ,
10+ error => http . onError ( error , this . instance ) ,
11+ ) ;
12+
813 this . instance . interceptors . response . use (
914 response => http . onResponse ( response , this . instance ) ,
1015 error => http . onError ( error , this . instance ) ,
@@ -15,8 +20,7 @@ export default class Axios {
1520
1621 setAuthentication ( token ) {
1722 if ( ! token ) return ;
18- const isFunction = typeof token
19- "function" ;
23+ const isFunction = typeof token === 'function' ;
2024 const tokenStr = isFunction ? token ( ) : token ;
2125
2226 this . instance . defaults . headers . common [ 'Authorization' ] = `Bearer ${ tokenStr } ` ;
Original file line number Diff line number Diff line change @@ -83,11 +83,21 @@ export const AxiosRequestConfig = {
8383 */
8484 proxy : { } ,
8585
86+ /**
87+ * Default onRequest
88+ * @param {object } config
89+ * @param {Axios } Axios instance
90+ */
91+ onRequest ( config , axios ) {
92+ return config ;
93+ } ,
94+
8695 /**
8796 * Default on Response
8897 * @param {object } response
98+ * @param {Axios } axios instance
8999 */
90- onResponse ( response ) {
100+ onResponse ( response , axios ) {
91101 return response . data ;
92102 } ,
93103
@@ -134,8 +144,9 @@ export const AxiosRequestConfig = {
134144 /**
135145 * Default on Error
136146 * @param {object } error
147+ * @param {Axios } axios instance
137148 */
138- onError ( error ) {
149+ onError ( error , axios ) {
139150 const { response } = error ;
140151 const errorTypes = {
141152 401 : this . onUnauthorised ,
You can’t perform that action at this time.
0 commit comments