diff --git a/src/runtime/composables/useMenu.ts b/src/runtime/composables/useMenu.ts index 1cbc62b..1335de6 100644 --- a/src/runtime/composables/useMenu.ts +++ b/src/runtime/composables/useMenu.ts @@ -1,10 +1,9 @@ -import { useFetch, createError, useRuntimeConfig, ref, useNuxtData, useNuxtApp } from "#imports" +import { useFetch, useRuntimeConfig, ref, useNuxtData, useNuxtApp } from "#imports" import { useTokens } from "./useTokens" -import { useWPNuxtLogger } from "./useWPNuxtlogger"; +import type { GraphqlResponse } from "~/src/types"; const _useMenu = async (name?: string) => { const menu = ref() - const logger = useWPNuxtLogger() const config = useRuntimeConfig() const nuxtApp = useNuxtApp() const menuName = name && name.length > 0 ? name : config.public.wpNuxt.defaultMenuName @@ -15,29 +14,26 @@ const _useMenu = async (name?: string) => { if (cachedMenu.value) { menu.value = cachedMenu.value } else { - const { data, error } = await useFetch('/api/graphql_middleware/query/Menu', { - params: { - name: menuName - }, - key: cacheKey, - headers: { - Authorization: tokens.authorizationHeader - }, - transform (data: any) { - return data.data.menu.menuItems.nodes; - }, - getCachedData(key: string) { - return nuxtApp.payload.data[key] || nuxtApp.static.data[key] - } - }); - if (error.value) { - logger.error('useMenu, error: ', error.value) - throw createError({ statusCode: error.value.status, message: error.value.message, fatal: true }) - } - menu.value = data.value - } - return { - data: menu.value + return useFetch>("/api/graphql_middleware/query/Menu", { + params: { + name: menuName + }, + key: cacheKey, + headers: { + Authorization: tokens.authorizationHeader + }, + transform (data: any) { + return data.data.menu.menuItems.nodes; + }, + getCachedData(key: string) { + return nuxtApp.payload.data[key] || nuxtApp.static.data[key] + } + }).then((v: GraphqlResponse) => { + return { + data: v.data.value, + errors: v.errors || [], + } + }) } }