Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: revert axios interceptor and use normal time data - fixed #1449

Liyas Thomas2b2c968a97b8
diff --git a/helpers/strategies/AxiosStrategy.js b/helpers/strategies/AxiosStrategy.js
index 694d8e8e8..42f30c25a 100644
--- a/helpers/strategies/AxiosStrategy.js
+++ b/helpers/strategies/AxiosStrategy.js
@@ -1,26 +1,6 @@
import axios from "axios"
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()
export const cancelRunningAxiosRequest = () => {
diff --git a/pages/index.vue b/pages/index.vue
index 63b2f6e67..0de570028 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -1400,6 +1400,7 @@ export default {
if (headers[id].key) headersObject[headers[id].key] = headers[id].value
})
headers = headersObject
+ const startTime = new Date().getTime()
try {
this.runningRequest = true
const payload = await this.makeRequest(
@@ -1409,7 +1410,7 @@ export default {
this.showPreRequestScript && this.preRequestScript
)
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.size = payload.headers["content-length"]
;(() => {
@@ -1461,13 +1462,15 @@ export default {
})()
} catch (error) {
this.runningRequest = false
-
// If the error is caused by cancellation, do nothing
if (error === "cancellation") {
this.response.status = this.$t("cancelled")
this.response.body = this.$t("cancelled")
} else {
console.log(error)
+ const duration = new Date().getTime() - startTime
+ this.response.duration = duration
+ this.response.size = Buffer.byteLength(JSON.stringify(error))
if (error.response) {
this.response.headers = error.response.headers
this.response.status = error.response.status