ResponseMeta.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div
  3. class="sticky top-0 z-10 flex items-start p-4 overflow-auto bg-primary hide-scrollbar whitespace-nowrap"
  4. >
  5. <div
  6. v-if="response == null"
  7. class="flex flex-col items-center justify-center flex-1 text-secondaryLight"
  8. >
  9. <div class="flex pb-4 my-4 space-x-2">
  10. <div class="flex flex-col items-end text-right space-y-4">
  11. <span class="flex items-center flex-1">
  12. {{ t("shortcut.request.send_request") }}
  13. </span>
  14. <span class="flex items-center flex-1">
  15. {{ t("shortcut.general.show_all") }}
  16. </span>
  17. <span class="flex items-center flex-1">
  18. {{ t("shortcut.general.command_menu") }}
  19. </span>
  20. <span class="flex items-center flex-1">
  21. {{ t("shortcut.general.help_menu") }}
  22. </span>
  23. </div>
  24. <div class="flex flex-col space-y-4">
  25. <div class="flex">
  26. <span class="shortcut-key">{{ getSpecialKey() }}</span>
  27. <span class="shortcut-key">G</span>
  28. </div>
  29. <div class="flex">
  30. <span class="shortcut-key">{{ getSpecialKey() }}</span>
  31. <span class="shortcut-key">K</span>
  32. </div>
  33. <div class="flex">
  34. <span class="shortcut-key">/</span>
  35. </div>
  36. <div class="flex">
  37. <span class="shortcut-key">?</span>
  38. </div>
  39. </div>
  40. </div>
  41. <ButtonSecondary
  42. :label="t('app.documentation')"
  43. to="https://docs.hoppscotch.io/features/response"
  44. svg="external-link"
  45. blank
  46. outline
  47. reverse
  48. />
  49. </div>
  50. <div v-else class="flex flex-col flex-1">
  51. <div
  52. v-if="response.type === 'loading'"
  53. class="flex flex-col items-center justify-center"
  54. >
  55. <SmartSpinner class="my-4" />
  56. <span class="text-secondaryLight">{{ t("state.loading") }}</span>
  57. </div>
  58. <div
  59. v-if="response.type === 'network_fail'"
  60. class="flex flex-col items-center justify-center flex-1 p-4"
  61. >
  62. <img
  63. :src="`/images/states/${$colorMode.value}/youre_lost.svg`"
  64. loading="lazy"
  65. class="inline-flex flex-col object-contain object-center w-32 h-32 my-4"
  66. :alt="`${t('error.network_fail')}`"
  67. />
  68. <span class="mb-2 font-semibold text-center">
  69. {{ t("error.network_fail") }}
  70. </span>
  71. <span
  72. class="max-w-sm mb-6 text-center whitespace-normal text-secondaryLight"
  73. >
  74. {{ t("helpers.network_fail") }}
  75. </span>
  76. <AppInterceptor class="border rounded border-dividerLight" />
  77. </div>
  78. <div
  79. v-if="response.type === 'script_fail'"
  80. class="flex flex-col items-center justify-center flex-1 p-4"
  81. >
  82. <img
  83. :src="`/images/states/${$colorMode.value}/youre_lost.svg`"
  84. loading="lazy"
  85. class="inline-flex flex-col object-contain object-center w-32 h-32 my-4"
  86. :alt="`${t('error.script_fail')}`"
  87. />
  88. <span class="mb-2 font-semibold text-center">
  89. {{ t("error.script_fail") }}
  90. </span>
  91. <span
  92. class="max-w-sm mb-6 text-center whitespace-normal text-secondaryLight"
  93. >
  94. {{ t("helpers.script_fail") }}
  95. </span>
  96. <div
  97. class="w-full px-4 py-2 overflow-auto font-mono text-red-400 whitespace-normal rounded bg-primaryLight"
  98. >
  99. {{ response.error.name }}: {{ response.error.message }}<br />
  100. {{ response.error.stack }}
  101. </div>
  102. </div>
  103. <div
  104. v-if="response.type === 'success' || response.type === 'fail'"
  105. class="flex items-center font-semibold text-tiny"
  106. >
  107. <div
  108. :class="statusCategory.className"
  109. class="inline-flex flex-1 space-x-4"
  110. >
  111. <span v-if="response.statusCode">
  112. <span class="text-secondary"> {{ t("response.status") }}: </span>
  113. {{ `${response.statusCode}\xA0 • \xA0`
  114. }}{{ getStatusCodeReasonPhrase(response.statusCode) }}
  115. </span>
  116. <span v-if="response.meta && response.meta.responseDuration">
  117. <span class="text-secondary"> {{ t("response.time") }}: </span>
  118. {{ `${response.meta.responseDuration} ms` }}
  119. </span>
  120. <span v-if="response.meta && response.meta.responseSize">
  121. <span class="text-secondary"> {{ t("response.size") }}: </span>
  122. {{ `${response.meta.responseSize} B` }}
  123. </span>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. </template>
  129. <script setup lang="ts">
  130. import { computed } from "@nuxtjs/composition-api"
  131. import findStatusGroup from "~/helpers/findStatusGroup"
  132. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  133. import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
  134. import { useI18n } from "~/helpers/utils/composables"
  135. import { getStatusCodeReasonPhrase } from "~/helpers/utils/statusCodes"
  136. const t = useI18n()
  137. const props = defineProps<{
  138. response: HoppRESTResponse
  139. }>()
  140. const statusCategory = computed(() => {
  141. if (
  142. props.response.type === "loading" ||
  143. props.response.type === "network_fail" ||
  144. props.response.type === "script_fail" ||
  145. props.response.type === "fail"
  146. )
  147. return {
  148. name: "error",
  149. className: "text-red-500",
  150. }
  151. return findStatusGroup(props.response.statusCode)
  152. })
  153. </script>