itizawa 5 лет назад
Родитель
Сommit
5e96070a69

+ 1 - 1
src/client/js/components/PageRenameModal.jsx

@@ -72,7 +72,7 @@ const PageRenameModal = (props) => {
       window.location.href = `${url.pathname}${url.search}`;
     }
     catch (err) {
-      setErrorCode(err.code);
+      setErrorCode(err[0].code);
       setErrorMessage(err.message);
     }
   }

+ 6 - 5
src/server/routes/apiv3/pages.js

@@ -6,6 +6,7 @@ const express = require('express');
 const pathUtils = require('growi-commons').pathUtils;
 
 const { body } = require('express-validator/check');
+const ErrorV3 = require('../../models/vo/error-apiv3');
 
 const router = express.Router();
 
@@ -164,7 +165,7 @@ module.exports = (crowi) => {
     };
 
     if (!Page.isCreatableName(newPagePath)) {
-      return res.apiv3Err(`Could not use the path '${newPagePath})'`, 409, 'invalid_path');
+      return res.apiv3Err(new ErrorV3(`Could not use the path '${newPagePath})'`, 'invalid_path'), 409);
     }
 
     // check whether path starts slash
@@ -173,7 +174,7 @@ module.exports = (crowi) => {
     const isExist = await Page.count({ path: newPagePath }) > 0;
     if (isExist) {
       // if page found, cannot cannot rename to that path
-      return res.apiv3Err(`'new_path=${newPagePath}' already exists`, 409, 'already_exists');
+      return res.apiv3Err(new ErrorV3(`'new_path=${newPagePath}' already exists`, 'already_exists'), 409);
     }
 
     let page;
@@ -182,11 +183,11 @@ module.exports = (crowi) => {
       page = await Page.findByIdAndViewer(pageId, req.user);
 
       if (page == null) {
-        return res.apiv3Err(`Page '${pageId}' is not found or forbidden`, 401, 'notfound_or_forbidden');
+        return res.apiv3Err(new ErrorV3(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'), 401);
       }
 
       if (!page.isUpdatable(revisionId)) {
-        return res.apiv3Err('Someone could update this page, so couldn\'t delete.', 409, 'notfound_or_forbidden');
+        return res.apiv3Err(new ErrorV3('Someone could update this page, so couldn\'t delete.', 'notfound_or_forbidden'), 409);
       }
 
       if (isRecursively) {
@@ -198,7 +199,7 @@ module.exports = (crowi) => {
     }
     catch (err) {
       logger.error(err);
-      return res.apiv3Err('Failed to update page.', 500, 'unknown');
+      return res.apiv3Err(new ErrorV3('Failed to update page.', 'unknown'), 500);
     }
 
     const result = { page: pageService.serializeToObj(page) };

+ 2 - 2
src/server/routes/apiv3/response.js

@@ -13,7 +13,7 @@ const addCustomFunctionToResponse = (express, crowi) => {
     this.json({ data: obj });
   };
 
-  express.response.apiv3Err = function(_err, status = 400, code) { // not arrow function
+  express.response.apiv3Err = function(_err, status = 400, info) { // not arrow function
     if (!Number.isInteger(status)) {
       throw new Error('invalid status supplied to res.apiv3Err');
     }
@@ -33,7 +33,7 @@ const addCustomFunctionToResponse = (express, crowi) => {
       throw new Error('invalid error supplied to res.apiv3Err');
     });
 
-    this.status(status).json({ errors, code });
+    this.status(status).json({ errors, info });
   };
 };