function ajax()

in shardingsphere-ui-frontend/src/utils/api.js [25:70]


function ajax(url, type, options, config) {
  return new Promise((resolve, reject) => {
    axios({
      method: type,
      url: config ? C[config.host] + url : C.HOST + url,
      timeout: 10000,
      headers: {
        'Access-Token': window.localStorage.getItem('Access-Token') || ''
      },
      params: type === 'get' ? options : null,
      data: options
    })
      .then(result => {
        const data = result.data
        const success = data.success
        if (success) {
          resolve(data)
          return
        }

        if (!success) {
          if (data.errorCode === 403) {
            const store = window.localStorage
            store.removeItem('Access-Token')
            store.removeItem('username')
            location.href = '#/login'
            return
          }
          reject(data)
          Message({
            message: data.errorMsg,
            type: 'error',
            duration: 2 * 1000
          })
          return
        }
      })
      .catch(error => {
        Message({
          message: error,
          type: 'error',
          duration: 2 * 1000
        })
      })
  })
}