Jelajahi Sumber

add exception

yohei0125 4 tahun lalu
induk
melakukan
5e21e373b0
1 mengubah file dengan 5 tambahan dan 0 penghapusan
  1. 5 0
      packages/app/src/server/service/page.ts

+ 5 - 0
packages/app/src/server/service/page.ts

@@ -665,6 +665,11 @@ class PageService {
    * Duplicate
    */
   async duplicate(page, newPagePath, user, isRecursively) {
+    const isEmptyAndNotRecursively = page?.isEmpty && !isRecursively;
+    if (page == null || isEmptyAndNotRecursively) {
+      throw new Error('Cannot find or duplicate the empty page');
+    }
+
     const Page = mongoose.model('Page') as unknown as PageModel;
     const PageTagRelation = mongoose.model('PageTagRelation') as any; // TODO: Typescriptize model