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

+ 5 - 5
src/client/js/components/PageDuplicateModal.jsx

@@ -24,7 +24,7 @@ const PageDuplicateModal = (props) => {
   const { crowi } = appContainer.config;
 
   const [pageNameInput, setPageNameInput] = useState(path);
-  const [errorMessage, setErrorMessage] = useState(null);
+  const [errorCode, setErrorCode] = useState(null);
 
   /**
    * change pageNameInput
@@ -36,13 +36,13 @@ const PageDuplicateModal = (props) => {
 
   async function clickDuplicateButtonHandler() {
     try {
-      setErrorMessage(null);
+      setErrorCode(null);
       const res = await appContainer.apiPost('/pages.duplicate', { page_id: pageId, new_path: pageNameInput });
       const { page } = res;
       window.location.href = encodeURI(urljoin(page.path, '?duplicated=', path));
     }
     catch (err) {
-      setErrorMessage(err.message);
+      setErrorCode(err.message);
     }
   }
 
@@ -63,7 +63,7 @@ const PageDuplicateModal = (props) => {
             <div className="input-group-prepend">
               <span className="input-group-text">{crowi.url}</span>
             </div>
-            {isReachable
+            {!isReachable
               // GW-2355 refactor typeahead
               ? <PagePathAutoComplete crowi={appContainer} initializedPath={path} addTrailingSlash />
               : (
@@ -79,7 +79,7 @@ const PageDuplicateModal = (props) => {
         </div>
       </ModalBody>
       <ModalFooter>
-        <ApiErrorMessage errorMessage={errorMessage} linkPath={path} />
+        <ApiErrorMessage errorCode={errorCode} linkPath={path} />
         <button type="button" className="btn btn-primary" onClick={clickDuplicateButtonHandler}>Duplicate page</button>
       </ModalFooter>
     </Modal>

+ 4 - 4
src/client/js/components/PageManagement/ApiErrorMessage.jsx

@@ -4,11 +4,11 @@ import PropTypes from 'prop-types';
 import { withTranslation } from 'react-i18next';
 
 const ApiErrorMessage = (props) => {
-  const { t, errorMessage, linkPath } = props;
+  const { t, errorCode, linkPath } = props;
 
   function renderMessage() {
-    switch (errorMessage) {
-      case 'Page exists':
+    switch (errorCode) {
+      case 'already_exists':
         return (
           <span className="text-danger">
             <strong><i className="icon-fw icon-ban"></i>{ t('page_api_error.already_exists') }</strong>
@@ -52,7 +52,7 @@ const ApiErrorMessage = (props) => {
 
 ApiErrorMessage.propTypes = {
   t: PropTypes.func.isRequired, //  i18next
-  errorMessage: PropTypes.string,
+  errorCode: PropTypes.string,
   linkPath: PropTypes.string,
 };
 

+ 6 - 0
src/client/js/services/AppContainer.js

@@ -428,6 +428,12 @@ export default class AppContainer extends Container {
     if (res.data.ok) {
       return res.data;
     }
+
+    // Return error code if code is exist
+    if (res.data.code) {
+      throw new Error(res.data.code);
+    }
+
     throw new Error(res.data.error);
   }