App.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div>
  3. <div
  4. v-if="isLoadingInitialRoute"
  5. class="flex flex-col items-center justify-center min-h-screen"
  6. >
  7. <HoppSmartSpinner />
  8. </div>
  9. <ErrorPage v-if="errorInfo !== null" :error="errorInfo" />
  10. <RouterView v-else />
  11. </div>
  12. </template>
  13. <script setup lang="ts">
  14. import { ref } from "vue"
  15. import ErrorPage, { ErrorPageData } from "~/pages/_.vue"
  16. import { HOPP_MODULES } from "@modules/."
  17. import { isLoadingInitialRoute } from "@modules/router"
  18. import { useI18n } from "@composables/i18n"
  19. import { APP_IS_IN_DEV_MODE } from "@helpers/dev"
  20. import { platform } from "./platform"
  21. const t = useI18n()
  22. const errorInfo = ref<ErrorPageData | null>(null)
  23. // App Crash Handler
  24. // If the below code gets more complicated, move this onto a module
  25. const formatErrorMessage = (err: Error | null | undefined) => {
  26. if (!err) return null
  27. return `${err.name}: ${err.message}`
  28. }
  29. // App Crash Handler is only a thing in Dev Mode
  30. if (APP_IS_IN_DEV_MODE) {
  31. window.onerror = (_, _1, _2, _3, err) => {
  32. errorInfo.value = {
  33. statusCode: 500,
  34. message: formatErrorMessage(err) ?? t("error.something_went_wrong"),
  35. }
  36. // Returning false here will not cancel the error and will log it to console
  37. return false
  38. }
  39. }
  40. // Run module root component setup code
  41. HOPP_MODULES.forEach((mod) => mod.onRootSetup?.())
  42. platform.addedHoppModules?.forEach((mod) => mod.onRootSetup?.())
  43. </script>