Can Mini Program interceptor intercept on the request interface?

app.globalData.Authorization is the global variable that saves token

http({ url, data, method }) {
    return new Promise((resolve, reject) => {
      const app = getApp();
      wx.request({
        url: url,
        data: data,
        method,
        header: {"token": app.globalData.Authorization },
        success(res) {
          res.statusCode === 200 ? resolve(res.data) : reject(res.data);
          // 
        },
        fail(res) {
          reject(res)
        }
      })
    })
  }
}

API success is 200. you must skip to the success method, and if you fail, jump to the fail method. Of course, you can choose to judge again

Menu