import axios from 'axios'
import { Message } from 'element-ui'

const request = axios.create({ timeout: 5000 })

request.interceptors.response.use(
  res => {
    if (res.data.code !== 200) {
      Message.error(res.data.msg || '请求失败')
      return Promise.reject(res.data)
    }
    return res.data
  },
  err => {
    Message.error('网络错误')
    return Promise.reject(err)
  }
)

export default request
