Interceptors response exception catch problem of axios

axios.interceptors.response.use(
    response => {
        if (response.data.code === "OK") {
            return response
        } else if (response.data.code === "ERROR") {
            console.log(response.data.data)
            return Promise.reject(response.data)
        }    
    },
    error => {
        ...
    })

then encapsulate the axios with a layer

export const Common = {
  axios (url, params) {
    params = params || {}
    return axios.post(url, qs.stringify(params))
  }
}

use it

Common.axios("/api/a", { a: 1 }).then().catch(e => {})

catch exceptions every time. Can this catch exception be handled uniformly =. =

Apr.05,2021

this requirement is quite strange. Since you want to accept a promise, outside but do not want to catch the reject status of the promise, the promise can only return resolve or pending, forever.

export const Common = {
      axios(url, params) {
        let _resolve;
        let _reject;
        const p = new Promise((resolve, reject) => {
          _resolve = resolve;
          _reject = reject;
        })
        params = params || {};
        axios.post(url, qs.stringify(params)).then((res) => {
          _resolve(res)
        }).catch(err => {
          params.callback(err); // 
          _resolve(); //resolvepending
        })
        return p;
      }
}

else if (response.data.code === 'ERROR') {
             // 
            console.log(response.data.data)
            return Promise.reject(response.data)
        }    
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d91d-2bb1f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d91d-2bb1f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?