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: interceptor error from extension issue (#3548)

Nivedin8d7509cdea4e
diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json
index fd5eb94dc..836446fb0 100644
--- a/packages/hoppscotch-common/locales/en.json
+++ b/packages/hoppscotch-common/locales/en.json
@@ -257,6 +257,7 @@
"error": {
"browser_support_sse": "This browser doesn't seems to have Server Sent Events support.",
"check_console_details": "Check console log for details.",
+ "check_how_to_add_origin": "Check how you can add an origin",
"curl_invalid_format": "cURL is not formatted properly",
"danger_zone": "Danger zone",
"delete_account": "Your account is currently an owner in these teams:",
@@ -277,6 +278,7 @@
"no_environments_to_export": "No environments to export. Please create an environment to get started.",
"no_results_found": "No matches found",
"page_not_found": "This page could not be found",
+ "please_install_extension": "Please install the extension and add origin to the extension.",
"proxy_error": "Proxy error",
"script_fail": "Could not execute pre-request script",
"something_went_wrong": "Something went wrong",
diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts
index 786d61c73..5adf4db2c 100644
--- a/packages/hoppscotch-common/src/components.d.ts
+++ b/packages/hoppscotch-common/src/components.d.ts
@@ -1,11 +1,11 @@
-// generated by unplugin-vue-components
-// We suggest you to commit this file into source control
+/* eslint-disable */
+/* prettier-ignore */
+// @ts-nocheck
+// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
-import '@vue/runtime-core'
-
export {}
-declare module '@vue/runtime-core' {
+declare module 'vue' {
export interface GlobalComponents {
AppActionHandler: typeof import('./components/app/ActionHandler.vue')['default']
AppAnnouncement: typeof import('./components/app/Announcement.vue')['default']
@@ -154,6 +154,7 @@ declare module '@vue/runtime-core' {
IconLucideMinus: typeof import('~icons/lucide/minus')['default']
IconLucideSearch: typeof import('~icons/lucide/search')['default']
IconLucideUsers: typeof import('~icons/lucide/users')['default']
+ InterceptorsErrorPlaceholder: typeof import('./components/interceptors/ErrorPlaceholder.vue')['default']
InterceptorsExtensionSubtitle: typeof import('./components/interceptors/ExtensionSubtitle.vue')['default']
LensesHeadersRenderer: typeof import('./components/lenses/HeadersRenderer.vue')['default']
LensesHeadersRendererEntry: typeof import('./components/lenses/HeadersRendererEntry.vue')['default']
@@ -218,5 +219,4 @@ declare module '@vue/runtime-core' {
WorkspaceCurrent: typeof import('./components/workspace/Current.vue')['default']
WorkspaceSelector: typeof import('./components/workspace/Selector.vue')['default']
}
-
}
diff --git a/packages/hoppscotch-common/src/components/graphql/Sidebar.vue b/packages/hoppscotch-common/src/components/graphql/Sidebar.vue
index 84a15cfa9..c4a3e9dba 100644
--- a/packages/hoppscotch-common/src/components/graphql/Sidebar.vue
+++ b/packages/hoppscotch-common/src/components/graphql/Sidebar.vue
@@ -58,8 +58,8 @@
v-for="(field, index) in filteredQueryFields"
:key="`field-${index}`"
:gql-field="field"
- @jump-to-type="handleJumpToType"
class="p-4"
+ @jump-to-type="handleJumpToType"
/>
</HoppSmartTab>
<HoppSmartTab
@@ -72,8 +72,8 @@
v-for="(field, index) in filteredMutationFields"
:key="`field-${index}`"
:gql-field="field"
- @jump-to-type="handleJumpToType"
class="p-4"
+ @jump-to-type="handleJumpToType"
/>
</HoppSmartTab>
<HoppSmartTab
@@ -86,8 +86,8 @@
v-for="(field, index) in filteredSubscriptionFields"
:key="`field-${index}`"
:gql-field="field"
- @jump-to-type="handleJumpToType"
class="p-4"
+ @jump-to-type="handleJumpToType"
/>
</HoppSmartTab>
<HoppSmartTab
diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue
index 52e0a85a1..e1743987c 100644
--- a/packages/hoppscotch-common/src/components/http/Request.vue
+++ b/packages/hoppscotch-common/src/components/http/Request.vue
@@ -350,7 +350,6 @@ const newSendRequest = async () => {
const streamResult = await streamPromise
requestCancelFunc.value = cancel
-
if (E.isRight(streamResult)) {
subscribeToStream(
streamResult.right,
@@ -365,6 +364,20 @@ const newSendRequest = async () => {
loading.value = false
},
() => {
+ // TODO: Change this any to a proper type
+ const result = (streamResult.right as any).value
+ if (
+ result.type === "network_fail" &&
+ result.error?.error === "NO_PW_EXT_HOOK"
+ ) {
+ const errorResponse: HoppRESTResponse = {
+ type: "extension_error",
+ error: result.error.humanMessage.heading,
+ component: result.error.component,
+ req: result.req,
+ }
+ updateRESTResponse(errorResponse)
+ }
loading.value = false
}
)
diff --git a/packages/hoppscotch-common/src/components/http/ResponseMeta.vue b/packages/hoppscotch-common/src/components/http/ResponseMeta.vue
index 2d31fffeb..1bfb7d766 100644
--- a/packages/hoppscotch-common/src/components/http/ResponseMeta.vue
+++ b/packages/hoppscotch-common/src/components/http/ResponseMeta.vue
@@ -11,6 +11,12 @@
<HoppSmartSpinner class="my-4" />
<span class="text-secondaryLight">{{ t("state.loading") }}</span>
</div>
+
+ <component
+ :is="response.component"
+ v-if="response.type === 'extension_error'"
+ class="flex-1"
+ />
<HoppSmartPlaceholder
v-if="response.type === 'network_fail'"
:src="`/images/states/${colorMode.value}/youre_lost.svg`"
diff --git a/packages/hoppscotch-common/src/components/interceptors/ErrorPlaceholder.vue b/packages/hoppscotch-common/src/components/interceptors/ErrorPlaceholder.vue
new file mode 100644
index 000000000..d19b65784
--- /dev/null
+++ b/packages/hoppscotch-common/src/components/interceptors/ErrorPlaceholder.vue
@@ -0,0 +1,98 @@
+<template>
+ <HoppSmartPlaceholder
+ :src="`/images/states/${colorMode.value}/youre_lost.svg`"
+ :alt="`${t('error.network_fail')}`"
+ :heading="t('error.network_fail')"
+ large
+ >
+ <div class="my-1 text-secondaryLight flex flex-col items-center">
+ <span>
+ {{ t("error.please_install_extension") }}
+ </span>
+ <span>
+ {{ t("error.check_how_to_add_origin") }}
+ <HoppSmartLink
+ blank
+ to="https://docs.hoppscotch.io/documentation/features/interceptor#browser-extension"
+ class="text-accent hover:text-accentDark"
+ >
+ here
+ </HoppSmartLink>
+ </span>
+ </div>
+ <div class="flex flex-col py-4 space-y-2">
+ <span>
+ <HoppSmartItem
+ to="https://chrome.google.com/webstore/detail/hoppscotch-browser-extens/amknoiejhlmhancpahfcfcfhllgkpbld"
+ blank
+ :icon="IconChrome"
+ label="Chrome"
+ :info-icon="hasChromeExtInstalled ? IconCheckCircle : null"
+ :active-info-icon="hasChromeExtInstalled"
+ outline
+ />
+ </span>
+ <span>
+ <HoppSmartItem
+ to="https://addons.mozilla.org/en-US/firefox/addon/hoppscotch"
+ blank
+ :icon="IconFirefox"
+ label="Firefox"
+ :info-icon="hasFirefoxExtInstalled ? IconCheckCircle : null"
+ :active-info-icon="hasFirefoxExtInstalled"
+ outline
+ />
+ </span>
+ </div>
+ <div class="py-4 space-y-4">
+ <div class="flex items-center">
+ <HoppSmartToggle
+ :on="extensionEnabled"
+ @change="extensionEnabled = !extensionEnabled"
+ >
+ {{ t("settings.extensions_use_toggle") }}
+ </HoppSmartToggle>
+ </div>
+ </div>
+ </HoppSmartPlaceholder>
+</template>
+
+<script setup lang="ts">
+import IconChrome from "~icons/brands/chrome"
+import IconFirefox from "~icons/brands/firefox"
+import IconCheckCircle from "~icons/lucide/check-circle"
+import { useI18n } from "@composables/i18n"
+import { ExtensionInterceptorService } from "~/platform/std/interceptors/extension"
+import { useService } from "dioc/vue"
+import { computed } from "vue"
+import { InterceptorService } from "~/services/interceptor.service"
+import { platform } from "~/platform"
+import { useColorMode } from "~/composables/theming"
+
+const colorMode = useColorMode()
+const t = useI18n()
+
+const interceptorService = useService(InterceptorService)
+const extensionService = useService(ExtensionInterceptorService)
+
+const hasChromeExtInstalled = extensionService.chromeExtensionInstalled
+const hasFirefoxExtInstalled = extensionService.firefoxExtensionInstalled
+
+const extensionEnabled = computed({
+ get() {
+ return (
+ interceptorService.currentInterceptorID.value ===
+ extensionService.interceptorID
+ )
+ },
+ set(active) {
+ if (active) {
+ interceptorService.currentInterceptorID.value =
+ extensionService.interceptorID
+ } else {
+ interceptorService.currentInterceptorID.value =
+ platform.interceptors.default
+ }
+ },
+})
+</script>
diff --git a/packages/hoppscotch-common/src/composables/stream.ts b/packages/hoppscotch-common/src/composables/stream.ts
index b742a1bb3..32e26bedd 100644
--- a/packages/hoppscotch-common/src/composables/stream.ts
+++ b/packages/hoppscotch-common/src/composables/stream.ts
@@ -152,12 +152,14 @@ export function useStreamSubscriber(): {
error?: (e: any) => void,
complete?: () => void
) => {
- const sub = stream.subscribe({
+ let sub: Subscription | null = null
+
+ sub = stream.subscribe({
next,
error,
complete: () => {
if (complete) complete()
- subs.splice(subs.indexOf(sub), 1)
+ if (sub) subs.splice(subs.indexOf(sub), 1)
},
})
diff --git a/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts b/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts
index bb5141d4c..0bc894342 100644
--- a/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts
+++ b/packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts
@@ -1,4 +1,5 @@
import { HoppRESTRequest } from "@hoppscotch/data"
+import { Component } from "vue"
export type HoppRESTResponseHeader = { key: string; value: string }
@@ -39,3 +40,9 @@ export type HoppRESTResponse =
req: HoppRESTRequest
}
+ | {
+ type: "extension_error"
+ error: string
+ component: Component
+ req: HoppRESTRequest
+ }
diff --git a/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts b/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts
index 99caa6095..07ed237a8 100644
--- a/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts
+++ b/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts
@@ -12,6 +12,7 @@ import { computed, readonly, ref } from "vue"
import { browserIsChrome, browserIsFirefox } from "~/helpers/utils/userAgent"
import SettingsExtension from "~/components/settings/Extension.vue"
import InterceptorsExtensionSubtitle from "~/components/interceptors/ExtensionSubtitle.vue"
+import InterceptorsErrorPlaceholder from "~/components/interceptors/ErrorPlaceholder.vue"
export const defineSubscribableObject = <T extends object>(obj: T) => {
const proxyObject = {
@@ -217,6 +218,7 @@ export class ExtensionInterceptorService
description: () => "Heading not found",
},
error: "NO_PW_EXT_HOOK",
+ component: InterceptorsErrorPlaceholder,
})
}
diff --git a/packages/hoppscotch-common/src/services/interceptor.service.ts b/packages/hoppscotch-common/src/services/interceptor.service.ts
index 4ed5b113e..8abf0f3f7 100644
--- a/packages/hoppscotch-common/src/services/interceptor.service.ts
+++ b/packages/hoppscotch-common/src/services/interceptor.service.ts
@@ -29,6 +29,7 @@ export type InterceptorError =
description: (t: ReturnType<typeof getI18n>) => string
}
error?: unknown
+ component?: Component
}
/**