fix: revert axios interceptor and use normal time data - fixed #1449
This commit is contained in:
@@ -1,26 +1,6 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { decodeB64StringToArrayBuffer } from "../utils/b64"
|
import { decodeB64StringToArrayBuffer } from "../utils/b64"
|
||||||
|
|
||||||
axios.interceptors.request.use(
|
|
||||||
(config) => {
|
|
||||||
config.timeData = { startTime: new Date().getTime() }
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
return Promise.reject(error)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
axios.interceptors.response.use(
|
|
||||||
(response) => {
|
|
||||||
response.config.timeData.endTime = new Date().getTime()
|
|
||||||
return response
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
return Promise.reject(error)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
let cancelSource = axios.CancelToken.source()
|
let cancelSource = axios.CancelToken.source()
|
||||||
|
|
||||||
export const cancelRunningAxiosRequest = () => {
|
export const cancelRunningAxiosRequest = () => {
|
||||||
|
|||||||
@@ -1400,6 +1400,7 @@ export default {
|
|||||||
if (headers[id].key) headersObject[headers[id].key] = headers[id].value
|
if (headers[id].key) headersObject[headers[id].key] = headers[id].value
|
||||||
})
|
})
|
||||||
headers = headersObject
|
headers = headersObject
|
||||||
|
const startTime = new Date().getTime()
|
||||||
try {
|
try {
|
||||||
this.runningRequest = true
|
this.runningRequest = true
|
||||||
const payload = await this.makeRequest(
|
const payload = await this.makeRequest(
|
||||||
@@ -1409,7 +1410,7 @@ export default {
|
|||||||
this.showPreRequestScript && this.preRequestScript
|
this.showPreRequestScript && this.preRequestScript
|
||||||
)
|
)
|
||||||
this.runningRequest = false
|
this.runningRequest = false
|
||||||
const duration = payload.config.timeData.endTime - payload.config.timeData.startTime
|
const duration = new Date().getTime() - startTime
|
||||||
this.response.duration = duration
|
this.response.duration = duration
|
||||||
this.response.size = payload.headers["content-length"]
|
this.response.size = payload.headers["content-length"]
|
||||||
;(() => {
|
;(() => {
|
||||||
@@ -1461,13 +1462,15 @@ export default {
|
|||||||
})()
|
})()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.runningRequest = false
|
this.runningRequest = false
|
||||||
|
|
||||||
// If the error is caused by cancellation, do nothing
|
// If the error is caused by cancellation, do nothing
|
||||||
if (error === "cancellation") {
|
if (error === "cancellation") {
|
||||||
this.response.status = this.$t("cancelled")
|
this.response.status = this.$t("cancelled")
|
||||||
this.response.body = this.$t("cancelled")
|
this.response.body = this.$t("cancelled")
|
||||||
} else {
|
} else {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
const duration = new Date().getTime() - startTime
|
||||||
|
this.response.duration = duration
|
||||||
|
this.response.size = Buffer.byteLength(JSON.stringify(error))
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
this.response.headers = error.response.headers
|
this.response.headers = error.response.headers
|
||||||
this.response.status = error.response.status
|
this.response.status = error.response.status
|
||||||
|
|||||||
Reference in New Issue
Block a user