@storyblok/nuxt 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
- export function useAsyncStoryblok(url: any, apiOptions?: {}, bridgeOptions?: {}): Promise<any>;
1
+ import type { ISbStoriesParams, StoryblokBridgeConfigV2 } from '@storyblok/vue';
2
+ export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<any>;
@@ -1,30 +1,18 @@
1
1
  import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
2
- import { useAsyncData, useState, onMounted } from "#imports";
3
-
4
- export const useAsyncStoryblok = async (
5
- url,
6
- apiOptions = {},
7
- bridgeOptions = {}
8
- ) => {
2
+ import { useAsyncData, useState, onMounted, createError } from "#imports";
3
+ export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
9
4
  const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
10
- const story = useState(`${uniqueKey}-state`, () => null);
5
+ const story = useState(`${uniqueKey}-state`, () => ({}));
11
6
  const storyblokApiInstance = useStoryblokApi();
12
-
13
7
  onMounted(() => {
14
8
  if (story.value && story.value.id) {
15
- useStoryblokBridge(
16
- story.value.id,
17
- (evStory) => (story.value = evStory),
18
- bridgeOptions
19
- );
9
+ useStoryblokBridge(story.value.id, (evStory) => story.value = evStory, bridgeOptions);
20
10
  }
21
11
  });
22
-
23
- const { data } = await useAsyncData(
24
- `${uniqueKey}-asyncdata`,
25
- async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
26
- );
27
- story.value = data.value.data.story;
28
-
12
+ const { data, error } = await useAsyncData(`${uniqueKey}-asyncdata`, () => storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions));
13
+ if (error.value?.response.status >= 400 && error.value?.response.status < 600) {
14
+ throw createError({ statusCode: error.value?.response.status, statusMessage: error.value?.message.message });
15
+ }
16
+ story.value = data.value?.data.story;
29
17
  return story;
30
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "Storyblok Nuxt module",
5
5
  "type": "module",
6
6
  "exports": {