Explorar el Código

error handling

yohei0125 hace 3 años
padre
commit
a911aa8511

+ 9 - 5
packages/app/src/components/PageAlert/PageRedirectedAlert.tsx

@@ -2,6 +2,7 @@ import React, { useState, useCallback } from 'react';
 
 
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 
 
+import { toastError } from '~/client/util/apiNotification';
 import { useCurrentPagePath } from '~/stores/context';
 import { useCurrentPagePath } from '~/stores/context';
 import { useRedirectFrom } from '~/stores/page-redirect';
 import { useRedirectFrom } from '~/stores/page-redirect';
 
 
@@ -12,12 +13,15 @@ export const PageRedirectedAlert = React.memo((): JSX.Element => {
 
 
   const [isUnlinked, setIsUnlinked] = useState(false);
   const [isUnlinked, setIsUnlinked] = useState(false);
 
 
-  const unlinkButtonClickHandler = useCallback(() => {
+  const unlinkButtonClickHandler = useCallback(async() => {
     if (currentPagePath == null) return;
     if (currentPagePath == null) return;
-
-    unlink(currentPagePath);
-    setIsUnlinked(true);
-
+    try {
+      await unlink(currentPagePath);
+      setIsUnlinked(true);
+    }
+    catch (err) {
+      toastError(err);
+    }
   }, [currentPagePath, unlink]);
   }, [currentPagePath, unlink]);
 
 
   if (redirectFrom == null) {
   if (redirectFrom == null) {