mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
[file view] added 'catch' for requests
* added 'getErrorMsg' to utils.js
This commit is contained in:
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
|
|||||||
import watermark from 'watermark-dom';
|
import watermark from 'watermark-dom';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { siteName } from '../../utils/constants';
|
import { siteName } from '../../utils/constants';
|
||||||
|
import { Utils } from '../../utils/utils';
|
||||||
|
import toaster from '../toast';
|
||||||
import FileInfo from './file-info';
|
import FileInfo from './file-info';
|
||||||
import FileToolbar from './file-toolbar';
|
import FileToolbar from './file-toolbar';
|
||||||
import CommentPanel from './comment-panel';
|
import CommentPanel from './comment-panel';
|
||||||
@@ -45,12 +47,18 @@ class FileView extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
isStarred: false
|
isStarred: false
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
const errorMsg = Utils.getErrorMsg(error);
|
||||||
|
toaster.danger(errorMsg);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
seafileAPI.starItem(repoID, filePath).then((res) => {
|
seafileAPI.starItem(repoID, filePath).then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isStarred: true
|
isStarred: true
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
const errorMsg = Utils.getErrorMsg(error);
|
||||||
|
toaster.danger(errorMsg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,6 +70,9 @@ class FileView extends React.Component {
|
|||||||
isLocked: false,
|
isLocked: false,
|
||||||
lockedByMe: false
|
lockedByMe: false
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
const errorMsg = Utils.getErrorMsg(error);
|
||||||
|
toaster.danger(errorMsg);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
seafileAPI.lockfile(repoID, filePath).then((res) => {
|
seafileAPI.lockfile(repoID, filePath).then((res) => {
|
||||||
@@ -69,6 +80,9 @@ class FileView extends React.Component {
|
|||||||
isLocked: true,
|
isLocked: true,
|
||||||
lockedByMe: true
|
lockedByMe: true
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
const errorMsg = Utils.getErrorMsg(error);
|
||||||
|
toaster.danger(errorMsg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -734,6 +734,23 @@ export const Utils = {
|
|||||||
return items;
|
return items;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only used in the 'catch' part of a seafileAPI request
|
||||||
|
*/
|
||||||
|
getErrorMsg: function(error) {
|
||||||
|
let errorMsg = '';
|
||||||
|
if (error.response) {
|
||||||
|
if (error.response.data && error.response.data['error_msg']) {
|
||||||
|
errorMsg = error.response.data['error_msg'];
|
||||||
|
} else {
|
||||||
|
errorMsg = gettext('Error');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMsg = gettext('Please check the network.');
|
||||||
|
}
|
||||||
|
return errorMsg;
|
||||||
|
},
|
||||||
|
|
||||||
changeMarkdownNodes: function(nodes, fn) {
|
changeMarkdownNodes: function(nodes, fn) {
|
||||||
nodes.map((item) => {
|
nodes.map((item) => {
|
||||||
fn(item);
|
fn(item);
|
||||||
|
Reference in New Issue
Block a user