瀏覽代碼

add error handler

yusuketk 7 年之前
父節點
當前提交
fb7a221658
共有 2 個文件被更改,包括 34 次插入6 次删除
  1. 26 3
      src/client/js/components/Page/RevisionPath.js
  2. 8 3
      src/server/routes/page.js

+ 26 - 3
src/client/js/components/Page/RevisionPath.js

@@ -2,6 +2,7 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import Button from 'react-bootstrap/es/Button';
 import Modal from 'react-bootstrap/es/Modal';
+import * as toastr from 'toastr';
 import PageTagForm from '../PageTagForm';
 
 import CopyButton from '../CopyButton';
@@ -82,9 +83,31 @@ export default class RevisionPath extends React.Component {
     this.setState({ isOpenEditTagModal: true });
   }
 
-  async handleSubmitEditTagModal() {
-    this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newTags: this.state.newPageTags });
-    this.setState({ pageTags: this.state.newPageTags, isOpenEditTagModal: false });
+  handleSubmitEditTagModal() {
+    try {
+      this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newTags: this.state.newPageTags });
+      this.setState({ pageTags: this.state.newPageTags, isOpenEditTagModal: false });
+      toastr.success(undefined, 'Updated tags successfully', {
+        closeButton: true,
+        progressBar: true,
+        newestOnTop: false,
+        showDuration: '100',
+        hideDuration: '100',
+        timeOut: '1200',
+        extendedTimeOut: '150',
+      });
+    }
+    catch (err) {
+      toastr.error(err, 'Error occured on updating tags', {
+        closeButton: true,
+        progressBar: true,
+        newestOnTop: false,
+        showDuration: '100',
+        hideDuration: '100',
+        timeOut: '3000',
+      });
+    }
+
   }
 
   showToolTip() {

+ 8 - 3
src/server/routes/page.js

@@ -682,9 +682,14 @@ module.exports = function(crowi, app) {
   api.updateTags = async function(req, res) {
     const pageId = req.body.pageId;
     const newTags = req.body.newTags;
-    const page = await Page.findOne({ _id: pageId });
-    // update page tag
-    await page.updateTags(newTags);
+    try {
+      const page = await Page.findOne({ _id: pageId });
+      // update page tag
+      await page.updateTags(newTags);
+    }
+    catch (err) {
+      throw new Error('Error occured on updating tags');
+    }
   };
 
   /**