I define an Axios instance, my post request still can get response object even if i return false
when data.code == '10002'
import Axios from 'axios'
var axios = Axios.create({
headers: {
'Content-Type': 'application/json'
}
})
axios.interceptors.request.use(config=>{
config.headers['x-jwt-token'] = localStorage.getItem('token')
return config
}, error=>{
return Promise.reject(error)
})
axios.interceptors.response.use(function(response) {
if(response.data.code == '10002'){
//call RPC 过程ä¸ç¼ºå°‘å—æ®µ
app.$message.error('ç¼ºå°‘å—æ®µ' + response.data.message)
return
}
return response;
}, function(error) {
// Do something with response error
return Promise.reject(error);
});
Vue.prototype.$http = axios
You need to throw an error or return a rejected promise from your interceptor.
Also, you don't need to define the second parameter of use
if it just re-throws the error (not passing a second parameters has the same effect).
Most helpful comment
You need to throw an error or return a rejected promise from your interceptor.
Also, you don't need to define the second parameter of
use
if it just re-throws the error (not passing a second parameters has the same effect).