Răsfoiți Sursa

notify above catch

sou 7 ani în urmă
părinte
comite
80b47d9d55
1 a modificat fișierele cu 42 adăugiri și 40 ștergeri
  1. 42 40
      lib/routes/page.js

+ 42 - 40
lib/routes/page.js

@@ -1007,13 +1007,13 @@ module.exports = function(crowi, app) {
       res.json(ApiResponse.success(result));
       res.json(ApiResponse.success(result));
       return page;
       return page;
     })
     })
-    .catch(function(err) {
-      debug('Like failed', err);
-      return res.json(ApiResponse.error({}));
-    })
     .then((page) => {
     .then((page) => {
       // global notification
       // global notification
       return globalNotificationService.notifyPageLike(page, req.user);
       return globalNotificationService.notifyPageLike(page, req.user);
+    })
+    .catch(function(err) {
+      debug('Like failed', err);
+      return res.json(ApiResponse.error({}));
     });
     });
   };
   };
 
 
@@ -1086,45 +1086,47 @@ module.exports = function(crowi, app) {
     const isRecursively = (req.body.recursively !== undefined);
     const isRecursively = (req.body.recursively !== undefined);
 
 
     Page.findPageByIdAndGrantedUser(pageId, req.user)
     Page.findPageByIdAndGrantedUser(pageId, req.user)
-    .then(function(pageData) {
-      debug('Delete page', pageData._id, pageData.path);
+      .then(function(pageData) {
+        debug('Delete page', pageData._id, pageData.path);
 
 
-      if (isCompletely) {
-        if (isRecursively) {
-          return Page.completelyDeletePageRecursively(pageData, req.user);
-        }
-        else {
-          return Page.completelyDeletePage(pageData, req.user);
+        if (isCompletely) {
+          if (isRecursively) {
+            return Page.completelyDeletePageRecursively(pageData, req.user);
+          }
+          else {
+            return Page.completelyDeletePage(pageData, req.user);
+          }
         }
         }
-      }
 
 
-      // else
+        // else
 
 
-      if (!pageData.isUpdatable(previousRevision)) {
-        throw new Error('Someone could update this page, so couldn\'t delete.');
-      }
+        if (!pageData.isUpdatable(previousRevision)) {
+          throw new Error('Someone could update this page, so couldn\'t delete.');
+        }
 
 
-      if (isRecursively) {
-        return Page.deletePageRecursively(pageData, req.user);
-      }
-      else {
-        return Page.deletePage(pageData, req.user);
-      }
-    }).then(function(data) {
-      debug('Page deleted', data.path);
-      var result = {};
-      result.page = data;
+        if (isRecursively) {
+          return Page.deletePageRecursively(pageData, req.user);
+        }
+        else {
+          return Page.deletePage(pageData, req.user);
+        }
+      })
+      .then(function(data) {
+        debug('Page deleted', data.path);
+        var result = {};
+        result.page = data;
 
 
-      res.json(ApiResponse.success(result));
-      return data;
-    }).catch(function(err) {
-      debug('Error occured while get setting', err, err.stack);
-      return res.json(ApiResponse.error('Failed to delete page.'));
-    })
-    .then((page) => {
-      // global notification
-      return globalNotificationService.notifyPageDelete(page);
-    });
+        res.json(ApiResponse.success(result));
+        return data;
+      })
+      .then((page) => {
+        // global notification
+        return globalNotificationService.notifyPageDelete(page);
+      })
+      .catch(function(err) {
+        debug('Error occured while get setting', err, err.stack);
+        return res.json(ApiResponse.error('Failed to delete page.'));
+      });
   };
   };
 
 
   /**
   /**
@@ -1215,12 +1217,12 @@ module.exports = function(crowi, app) {
 
 
         return res.json(ApiResponse.success(result));
         return res.json(ApiResponse.success(result));
       })
       })
-      .catch(function(err) {
-        return res.json(ApiResponse.error('Failed to update page.'));
-      })
       .then(() => {
       .then(() => {
         // global notification
         // global notification
         globalNotificationService.notifyPageMove(page, req.body.path, req.user);
         globalNotificationService.notifyPageMove(page, req.body.path, req.user);
+      })
+      .catch(function(err) {
+        return res.json(ApiResponse.error('Failed to update page.'));
       });
       });
     });
     });