fix: problem that can't receive rejected message caused by interceptors; 🐛

修复:无法接受响应失败的消息;
master
iczer 4 years ago
parent 2021fb575d
commit d1f84218c6
  1. 8
      src/utils/request.js

@ -108,10 +108,10 @@ function loadInterceptors(interceptors, options) {
request.forEach(item => { request.forEach(item => {
let {onFulfilled, onRejected} = item let {onFulfilled, onRejected} = item
if (!onFulfilled || typeof onFulfilled !== 'function') { if (!onFulfilled || typeof onFulfilled !== 'function') {
onFulfilled = () => {} onFulfilled = config => config
} }
if (!onRejected || typeof onRejected !== 'function') { if (!onRejected || typeof onRejected !== 'function') {
onRejected = () => {} onRejected = error => Promise.reject(error)
} }
axios.interceptors.request.use( axios.interceptors.request.use(
config => onFulfilled(config, options), config => onFulfilled(config, options),
@ -122,10 +122,10 @@ function loadInterceptors(interceptors, options) {
response.forEach(item => { response.forEach(item => {
let {onFulfilled, onRejected} = item let {onFulfilled, onRejected} = item
if (!onFulfilled || typeof onFulfilled !== 'function') { if (!onFulfilled || typeof onFulfilled !== 'function') {
onFulfilled = () => {} onFulfilled = response => response
} }
if (!onRejected || typeof onRejected !== 'function') { if (!onRejected || typeof onRejected !== 'function') {
onRejected = () => {} onRejected = error => Promise.reject(error)
} }
axios.interceptors.response.use( axios.interceptors.response.use(
response => onFulfilled(response, options), response => onFulfilled(response, options),

Loading…
Cancel
Save