Yuki Takei 2 лет назад
Родитель
Сommit
c439bc95cb
1 измененных файлов с 16 добавлено и 7 удалено
  1. 16 7
      packages/remark-lsx/src/stores/lsx.tsx

+ 16 - 7
packages/remark-lsx/src/stores/lsx.tsx

@@ -100,13 +100,22 @@ const useSWRxLsxResponse = (
 ): SWRResponse<LsxResponse, Error> => {
   return useSWR(
     ['/_api/lsx', pagePath, options, isImmutable],
-    ([endpoint, pagePath, options]) => {
-      return axios.get(endpoint, {
-        params: {
-          pagePath,
-          options,
-        },
-      }).then(result => result.data as LsxResponse);
+    async([endpoint, pagePath, options]) => {
+      try {
+        const res = await axios.get<LsxResponse>(endpoint, {
+          params: {
+            pagePath,
+            options,
+          },
+        });
+        return res.data;
+      }
+      catch (err) {
+        if (axios.isAxiosError(err)) {
+          throw new Error(err.response?.data.message);
+        }
+        throw err;
+      }
     },
     {
       keepPreviousData: true,