Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
feat(common): display status text from the API response if available (#3466)
Gaurav K Ped2a461dc5c1
diff --git a/packages/hoppscotch-common/src/components/http/ResponseMeta.vue b/packages/hoppscotch-common/src/components/http/ResponseMeta.vueindex 1217ae518..ef246088e 100644--- a/packages/hoppscotch-common/src/components/http/ResponseMeta.vue+++ b/packages/hoppscotch-common/src/components/http/ResponseMeta.vue@@ -53,7 +53,12 @@<span v-if="response.statusCode"><span class="text-secondary"> {{ t("response.status") }}: </span>{{ `${response.statusCode}\xA0 • \xA0`- }}{{ getStatusCodeReasonPhrase(response.statusCode) }}+ }}{{+ getStatusCodeReasonPhrase(+ response.statusCode,+ response.statusText+ )+ }}</span><span v-if="response.meta && response.meta.responseDuration"><span class="text-secondary"> {{ t("response.time") }}: </span>diff --git a/packages/hoppscotch-common/src/helpers/network.ts b/packages/hoppscotch-common/src/helpers/network.tsindex 33d2f8d2f..6f70f9395 100644--- a/packages/hoppscotch-common/src/helpers/network.ts+++ b/packages/hoppscotch-common/src/helpers/network.ts@@ -29,10 +29,10 @@ function processResponse(const contentLength = res.headers["content-length"]? parseInt(res.headers["content-length"]): (res.data as ArrayBuffer).byteLength-return <HoppRESTResponse>{type: successState,statusCode: res.status,+ statusText: res.statusText,body: res.data,headers: Object.keys(res.headers).map((x) => ({key: x,diff --git a/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts b/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.tsindex 0bc894342..f5032d4d2 100644--- a/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts+++ b/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts@@ -10,7 +10,7 @@ export type HoppRESTResponse =headers: HoppRESTResponseHeader[]body: ArrayBufferstatusCode: number-+ statusText: stringmeta: {responseSize: number // in bytesresponseDuration: number // in millis@@ -33,6 +33,7 @@ export type HoppRESTResponse =headers: HoppRESTResponseHeader[]body: ArrayBufferstatusCode: number+ statusText: stringmeta: {responseSize: number // in bytesresponseDuration: number // in millisdiff --git a/packages/hoppscotch-common/src/helpers/utils/statusCodes.ts b/packages/hoppscotch-common/src/helpers/utils/statusCodes.tsindex e5f8996fd..34f1e12d2 100644--- a/packages/hoppscotch-common/src/helpers/utils/statusCodes.ts+++ b/packages/hoppscotch-common/src/helpers/utils/statusCodes.ts@@ -85,6 +85,17 @@ const statusCodes: {599: "Network connect timeout error", // (Unknown) This status code is not specified in any RFCs, but is used by Microsoft Corp. HTTP proxies to signal a network connect timeout behind the proxy to a client in front of the proxy.}-export function getStatusCodeReasonPhrase(code: number): string {+export function getStatusCodeReasonPhrase(+ code: number,+ statusText?: string+): string {+ // Return statusText if non-empty after trimming and add ellipsis if greater than 35 characters+ const trimmedStatusText = statusText?.trim()+ if (trimmedStatusText) {+ return trimmedStatusText.length > 35+ ? `${trimmedStatusText.substring(0, 35)}...`+ : trimmedStatusText+ }+return statusCodes[code] ?? "Unknown"}diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/response.inspector.spec.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/response.inspector.spec.tsindex 0f69a0d20..7ce9de007 100644--- a/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/response.inspector.spec.ts+++ b/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/response.inspector.spec.ts@@ -157,6 +157,7 @@ describe("ResponseInspectorService", () => {headers: [],meta: { responseDuration: 0, responseSize: 0 },req: req.value,+ statusText: "",})const result = responseInspector.getInspections(req, res)@@ -183,6 +184,7 @@ describe("ResponseInspectorService", () => {headers: [],meta: { responseDuration: 0, responseSize: 0 },req: req.value,+ statusText: "",})const result = responseInspector.getInspections(req, res)@@ -209,6 +211,7 @@ describe("ResponseInspectorService", () => {headers: [],meta: { responseDuration: 0, responseSize: 0 },req: req.value,+ statusText: "",})const result = responseInspector.getInspections(req, res)@@ -235,6 +238,7 @@ describe("ResponseInspectorService", () => {headers: [],meta: { responseDuration: 0, responseSize: 0 },req: req.value,+ statusText: "",})const result = responseInspector.getInspections(req, res)