Răsfoiți Sursa

page slack err handling

sou 7 ani în urmă
părinte
comite
48726d9cb4
2 a modificat fișierele cu 17 adăugiri și 11 ștergeri
  1. 5 8
      lib/routes/comment.js
  2. 12 3
      lib/routes/page.js

+ 5 - 8
lib/routes/comment.js

@@ -2,11 +2,11 @@ module.exports = function(crowi, app) {
   'use strict';
   'use strict';
 
 
   const debug = require('debug')('growi:routs:comment')
   const debug = require('debug')('growi:routs:comment')
+    , logger = require('@alias/logger')('growi:routes:comment')
     , Comment = crowi.model('Comment')
     , Comment = crowi.model('Comment')
     , User = crowi.model('User')
     , User = crowi.model('User')
     , Page = crowi.model('Page')
     , Page = crowi.model('Page')
     , ApiResponse = require('../util/apiResponse')
     , ApiResponse = require('../util/apiResponse')
-    , logger = require('@alias/logger')('growi:routes:comment')
     , actions = {}
     , actions = {}
     , api = {};
     , api = {};
 
 
@@ -86,12 +86,9 @@ module.exports = function(crowi, app) {
       const channels = slackNotificationForm.slackChannels;
       const channels = slackNotificationForm.slackChannels;
 
 
       if (channels) {
       if (channels) {
-        try {
-          page.updateSlackChannel(channels).then(function() {});
-        }
-        catch (err) {
-          logger.error('error occured in updating slack channels: ', err);
-        }
+        page.updateSlackChannel(channels).catch(err => {
+          logger.error('Error occured in updating slack channels: ', err);
+        });
 
 
         const promises = channels.split(',').map(function(chan) {
         const promises = channels.split(',').map(function(chan) {
           return crowi.slack.postComment(createdComment, user, chan, path);
           return crowi.slack.postComment(createdComment, user, chan, path);
@@ -99,7 +96,7 @@ module.exports = function(crowi, app) {
 
 
         Promise.all(promises)
         Promise.all(promises)
           .catch(err => {
           .catch(err => {
-            logger.error('error occured in sending slack notification: ', err);
+            logger.error('Error occured in sending slack notification: ', err);
           });
           });
       }
       }
     }
     }

+ 12 - 3
lib/routes/page.js

@@ -2,6 +2,7 @@ module.exports = function(crowi, app) {
   'use strict';
   'use strict';
 
 
   var debug = require('debug')('growi:routes:page')
   var debug = require('debug')('growi:routes:page')
+    , logger = require('@alias/logger')('growi:routes:page')
     , Page = crowi.model('Page')
     , Page = crowi.model('Page')
     , User = crowi.model('User')
     , User = crowi.model('User')
     , Config   = crowi.model('Config')
     , Config   = crowi.model('Config')
@@ -690,11 +691,19 @@ module.exports = function(crowi, app) {
       // TODO: move to events
       // TODO: move to events
       if (notify.slack) {
       if (notify.slack) {
         if (notify.slack.on && notify.slack.channel) {
         if (notify.slack.on && notify.slack.channel) {
-          data.updateSlackChannel(notify.slack.channel).then(function() {}).catch(function() {});
+          data.updateSlackChannel(notify.slack.channel)
+          .catch(err => {
+            logger.error('Error occured in updating slack channels: ', err);
+          });
 
 
           if (crowi.slack) {
           if (crowi.slack) {
-            notify.slack.channel.split(',').map(function(chan) {
-              crowi.slack.postPage(pageData, req.user, chan, updateOrCreate, previousRevision);
+            const promises = notify.slack.channel.split(',').map(function(chan) {
+              return crowi.slack.postPage(pageData, req.user, chan, updateOrCreate, previousRevision);
+            });
+
+            Promise.all(promises)
+            .catch(err => {
+              logger.error('Error occured in sending slack notification: ', err);
             });
             });
           }
           }
         }
         }