This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import axios from 'axios'
|
||||
import { token } from '@/common/token'
|
||||
import status from './status'
|
||||
const STATUS = status
|
||||
import app from '@/main'
|
||||
|
||||
axios.defaults.baseURL = '/api'
|
||||
@@ -28,7 +29,7 @@ const initInstance = (options) => {
|
||||
})
|
||||
|
||||
instance.interceptors.response.use((res) => {
|
||||
if (res.data.status === status.Unauthorized) {
|
||||
if (res.data.status === STATUS.Unauthorized) {
|
||||
handlerUnauthorized()
|
||||
}
|
||||
return res
|
||||
@@ -38,7 +39,7 @@ const initInstance = (options) => {
|
||||
return instance
|
||||
}
|
||||
|
||||
const errerCodes = [status.BadRequest, status.InternalServerError, status.Forbidden]
|
||||
const errerCodes = [STATUS.BadRequest, STATUS.InternalServerError, STATUS.Forbidden]
|
||||
|
||||
const errorNotification = ({ code, message }) => {
|
||||
switch (message.constructor) {
|
||||
@@ -111,7 +112,7 @@ for (let key in urls) {
|
||||
if (errerCodes.indexOf(data.code) >= 0) {
|
||||
errorNotification(data)
|
||||
reject([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data)
|
||||
} else if (data.code === status.Unauthorized) {
|
||||
} else if (data.code === STATUS.Unauthorized) {
|
||||
handlerUnauthorized()
|
||||
} else {
|
||||
reslove([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data)
|
||||
@@ -128,10 +129,10 @@ for (let key in urls) {
|
||||
} else {
|
||||
errorNotification(data)
|
||||
}
|
||||
reject(data)
|
||||
if (data.code === status.Unauthorized) {
|
||||
if (data.code === STATUS.Unauthorized) {
|
||||
handlerUnauthorized()
|
||||
}
|
||||
reject(data)
|
||||
} else {
|
||||
errorNotification({
|
||||
message: '系统发生错误,请联系管理员'
|
||||
@@ -160,5 +161,5 @@ api.$queue = function (queue) {
|
||||
export {
|
||||
axios,
|
||||
api,
|
||||
status
|
||||
STATUS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user