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) { async getChartData (value) {
await get(api.chart, { panelId: value }).then(response => { await axios.get(api.chart, { params: { panelId: value } }).then(response => {
if (response.code === 200) { if (response.status === 200) {
this.chartData = response.data.list this.chartData = response.data.data.list
} }
}) })
} }

View File

@@ -69,6 +69,13 @@ axios.interceptors.response.use(
return response return response
}, },
error => { 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) return Promise.reject(error)
} }
) )

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -67,9 +67,9 @@ export default {
endTime: this.timeFilter && this.timeFilter.endTime ? getSecond(this.timeFilter.endTime) : '' endTime: this.timeFilter && this.timeFilter.endTime ? getSecond(this.timeFilter.endTime) : ''
} }
this.toggleLoading(true) this.toggleLoading(true)
axios.get(api.netWorkOverview.ddosEventAnalysis, { params: params }).then(res => { axios.get(api.netWorkOverview.ddosEventAnalysis, { params: params }).then(response => {
res = res.data const res = response.data
if (res.code === 200) { if (response.status === 200) {
this.showError = false this.showError = false
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
this.ddosData = res.data.result[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 } }) const lastCycleTrafficRequest = axios.get(api.npm.overview.appTrafficAnalysis, { params: { ...params, cycle: 1 } })
this.toggleLoading(true) this.toggleLoading(true)
Promise.all([currentTrafficRequest, lastCycleTrafficRequest]).then(res => { 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.showError = false
this.errorMsg = '' this.errorMsg = ''
const prevData = res[1].data.data.result const prevData = res[1].data.data.result
@@ -234,7 +234,7 @@ export default {
let msg = '' let msg = ''
res.forEach((r, i) => { res.forEach((r, i) => {
if (r.data.code === 200) { if (r.status === 200) {
tableData.forEach(t => { tableData.forEach(t => {
t[keyPre[i] + 'Score'] = r.data.data.result.find(d => d.appSubcategory === t.appSubcategory) t[keyPre[i] + 'Score'] = r.data.data.result.find(d => d.appSubcategory === t.appSubcategory)
}) })
@@ -273,7 +273,7 @@ export default {
this.toggleLoading(false) this.toggleLoading(false)
this.showError = true this.showError = true
this.errorMsg = '' this.errorMsg = ''
let msg = res[0].message + ', ' + res[1].message let msg = res[0].data.message + ', ' + res[1].data.message
if (msg.indexOf(',') === 0) { if (msg.indexOf(',') === 0) {
msg = msg.substring(1, msg.length) msg = msg.substring(1, msg.length)
} }

View File

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

View File

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

View File

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

View File

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