fix: axios response超时逻辑变更

This commit is contained in:
chenjinsong
2023-08-25 16:23:18 +08:00
parent 26352f1b9c
commit dc6b8e067c
13 changed files with 38 additions and 31 deletions

View File

@@ -397,9 +397,9 @@ export default {
})
},
async getChartData (value) {
await get(api.chart, { panelId: value }).then(response => {
if (response.code === 200) {
this.chartData = response.data.list
await axios.get(api.chart, { params: { panelId: value } }).then(response => {
if (response.status === 200) {
this.chartData = response.data.data.list
}
})
}

View File

@@ -69,6 +69,13 @@ axios.interceptors.response.use(
return response
},
error => {
if (licenceErrorCode.indexOf(error.response.data.code) !== -1) {
localStorage.removeItem(storageKey.token)
window.location.href = '/'
} else if (accountErrorCode.indexOf(error.response.data.code) !== -1) {
localStorage.removeItem(storageKey.token)
window.location.href = '/'
}
return Promise.reject(error)
}
)

View File

@@ -142,13 +142,13 @@ export default {
Promise.all([data1, data2, data3]).then(res => {
const res0 = res[0].data
const res1 = res[1].data
if (res0.code === 200 && res1.code === 200) {
if (res[0].status === 200 && res[1].status === 200) {
this.isNoData = res0.data.result.length === 0 && res1.data.result.length === 0
}
// app相关显示ip、domain
if (this.entity.entityType === 'app' && !this.isNoData) {
if (res0.code === 200) {
if (res[0].status === 200) {
this.relatedIpList = res0.data.result
this.handleShowDataNum(this.showRelatedIpListInfo, this.relatedIpList)
} else {
@@ -156,7 +156,7 @@ export default {
this.errorMsg1 = this.errorMsgHandler(res0)
}
if (res1.code === 200) {
if (res[1].status === 200) {
this.relatedDomainList = res1.data.result
this.handleShowDataNum(this.showRelatedDomainListInfo, this.relatedDomainList)
} else {
@@ -170,14 +170,14 @@ export default {
// ip相关显示appdomain
if (this.entity.entityType === 'ip' && !this.isNoData) {
if (res0.code === 200) {
if (res[0].status === 200) {
this.relatedAppList = res0.data.result
this.handleShowDataNum(this.showRelatedAppListInfo, this.relatedAppList)
} else {
this.showError0 = true
this.errorMsg0 = this.errorMsgHandler(res0)
}
if (res1.code === 200) {
if (res[1].status === 200) {
this.relatedDomainList = res1.data.result
this.handleShowDataNum(this.showRelatedDomainListInfo, this.relatedDomainList)
} else {
@@ -192,11 +192,11 @@ export default {
// domain相关显示appipdomain
if (this.entity.entityType === 'domain') {
const res2 = res[2].data
if (res0.code === 200 && res1.code === 200 && res2.code === 200) {
if (res[0].status === 200 && res[1].status === 200 && res[2].status === 200) {
this.isNoData = res0.data.result.length === 0 && res1.data.result.length === 0 && res2.data.result.length === 0
}
if (res0.code === 200) {
if (res[0].status === 200) {
this.relatedAppList = res0.data.result
this.handleShowDataNum(this.showRelatedAppListInfo, this.relatedAppList)
} else {
@@ -204,7 +204,7 @@ export default {
this.errorMsg0 = this.errorMsgHandler(res0)
}
if (res1.code === 200) {
if (res[1].status === 200) {
this.relatedIpList = res1.data.result
this.handleShowDataNum(this.showRelatedIpListInfo, this.relatedIpList)
} else {
@@ -212,7 +212,7 @@ export default {
this.errorMsg1 = this.errorMsgHandler(res1)
}
if (res2.code === 200) {
if (res[2].status === 200) {
this.relatedDomainList = res2.data.result
this.handleShowDataNum(this.showRelatedDomainListInfo, this.relatedDomainList)
} else {
@@ -222,7 +222,7 @@ export default {
this.$emit('checkTag', entityDetailTabsName.relatedEntity, res0.data.result.length + res1.data.result.length + res2.data.result.length)
}
}).catch(e => {
console.log(e)
console.error(e)
this.$emit('checkTag', entityDetailTabsName.relatedEntity, 0)
this.showError0 = true
this.showError1 = true

View File

@@ -64,7 +64,7 @@ export default {
const url = this.getUrlByEntityType(this.entity.entityType)
axios.get(url, { params: params }).then(response => {
const res = response.data
if (res.code === 200) {
if (response.status === 200) {
this.isNoData = res.data.result.length === 0
this.$emit('checkTag', entityDetailTabsName.openPort, res.data.result.length)
this.showError = false

View File

@@ -101,7 +101,7 @@ export default {
axios.get(`${api.entity.performance}/${this.entityType}`, { params: params }).then(response => {
const res = response.data
if (res.code === 200) {
if (response.status === 200) {
this.isNoData = res.data.result.length === 0
this.$emit('checkTag', entityDetailTabsName.performanceEvent, res.data.result.length)
this.showError = false

View File

@@ -126,7 +126,7 @@ export default {
axios.get(`${api.entity.security}/${this.entityType}`, { params: params }).then(response => {
const res = response.data
if (res.code === 200) {
if (response.status === 200) {
this.isNoData = res.data.result.length === 0
this.$emit('checkTag', entityDetailTabsName.securityEvent, res.data.result.length)
this.showError = false

View File

@@ -69,11 +69,11 @@ export default {
this.toggleLoading(true)
Promise.all([dataRequest, nextHopRequest]).then(response => {
if (response[0] && response[1]) {
if (response[0].status === 200 && response[1].status === 200) {
const res = []
res[0] = response[0].data
res[1] = response[1].data
if (res[0].code === 200) {
if (response[0].status === 200) {
this.isLinkShowError = false
// 链路流量数据
const linkData = res[0].data.result
@@ -147,7 +147,7 @@ export default {
this.linkErrorMsg = this.errorMsgHandler(res[0])
}
if (res[1].code === 200) {
if (response[1].status === 200) {
this.isNextShowError = false
// 链路下一跳信息

View File

@@ -67,9 +67,9 @@ export default {
endTime: this.timeFilter && this.timeFilter.endTime ? getSecond(this.timeFilter.endTime) : ''
}
this.toggleLoading(true)
axios.get(api.netWorkOverview.ddosEventAnalysis, { params: params }).then(res => {
res = res.data
if (res.code === 200) {
axios.get(api.netWorkOverview.ddosEventAnalysis, { params: params }).then(response => {
const res = response.data
if (response.status === 200) {
this.showError = false
this.isNoData = res.data.result.length === 0
this.ddosData = res.data.result[0]

View File

@@ -198,7 +198,7 @@ export default {
const lastCycleTrafficRequest = axios.get(api.npm.overview.appTrafficAnalysis, { params: { ...params, cycle: 1 } })
this.toggleLoading(true)
Promise.all([currentTrafficRequest, lastCycleTrafficRequest]).then(res => {
if (res[0].data.code === 200 && res[1].data.code === 200) {
if (res[0].status === 200 && res[1].status === 200) {
this.showError = false
this.errorMsg = ''
const prevData = res[1].data.data.result
@@ -234,7 +234,7 @@ export default {
let msg = ''
res.forEach((r, i) => {
if (r.data.code === 200) {
if (r.status === 200) {
tableData.forEach(t => {
t[keyPre[i] + 'Score'] = r.data.data.result.find(d => d.appSubcategory === t.appSubcategory)
})
@@ -273,7 +273,7 @@ export default {
this.toggleLoading(false)
this.showError = true
this.errorMsg = ''
let msg = res[0].message + ', ' + res[1].message
let msg = res[0].data.message + ', ' + res[1].data.message
if (msg.indexOf(',') === 0) {
msg = msg.substring(1, msg.length)
}

View File

@@ -123,7 +123,7 @@ export default {
countryRegion: this.location
}
axios.get(api.npm.location.map, { params: params }).then(response => {
if (response.data.code === 200) {
if (response.status === 200) {
const res = _.get(response, 'data.data.result', []).filter(r => r.countryRegion !== 'Unknown')
if (res.length > 0) {
// 计算分数

View File

@@ -109,9 +109,9 @@ export default {
}
this.toggleLoading(true)
axios.get(url, { params: params }).then(res => {
res = res.data
if (res.code === 200) {
axios.get(url, { params: params }).then(response => {
const res = response.data
if (response.status === 200) {
this.showError = false
this.isNoData = res.data.result.length === 0
res.data.result.forEach(e => {

View File

@@ -206,7 +206,7 @@ export default {
})
// axios.post('api', formObj).then(response => {
// if (response.data.code === 200) {
// if (response.status === 200) {
// this.$message({
// duration: 2000,
// type: 'success',

View File

@@ -208,7 +208,7 @@ export default {
// todo 调用接口删除
// this.toggleLoading(true)
// axios.delete(api.detection.delete + '?ruleIds=' + ids).then(response => {
// if (response.data.code === 200) {
// if (response.status === 200) {
// this.delFlag = true
// this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
// this.secondBatchDeleteObjs.forEach((item) => {