mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 18:30:53 +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 { seafileAPI } from '../../utils/seafile-api';
|
||||
import { siteName } from '../../utils/constants';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import toaster from '../toast';
|
||||
import FileInfo from './file-info';
|
||||
import FileToolbar from './file-toolbar';
|
||||
import CommentPanel from './comment-panel';
|
||||
@@ -45,12 +47,18 @@ class FileView extends React.Component {
|
||||
this.setState({
|
||||
isStarred: false
|
||||
});
|
||||
}).catch((error) => {
|
||||
const errorMsg = Utils.getErrorMsg(error);
|
||||
toaster.danger(errorMsg);
|
||||
});
|
||||
} else {
|
||||
seafileAPI.starItem(repoID, filePath).then((res) => {
|
||||
this.setState({
|
||||
isStarred: true
|
||||
});
|
||||
}).catch((error) => {
|
||||
const errorMsg = Utils.getErrorMsg(error);
|
||||
toaster.danger(errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -62,6 +70,9 @@ class FileView extends React.Component {
|
||||
isLocked: false,
|
||||
lockedByMe: false
|
||||
});
|
||||
}).catch((error) => {
|
||||
const errorMsg = Utils.getErrorMsg(error);
|
||||
toaster.danger(errorMsg);
|
||||
});
|
||||
} else {
|
||||
seafileAPI.lockfile(repoID, filePath).then((res) => {
|
||||
@@ -69,6 +80,9 @@ class FileView extends React.Component {
|
||||
isLocked: true,
|
||||
lockedByMe: true
|
||||
});
|
||||
}).catch((error) => {
|
||||
const errorMsg = Utils.getErrorMsg(error);
|
||||
toaster.danger(errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -734,6 +734,23 @@ export const Utils = {
|
||||
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) {
|
||||
nodes.map((item) => {
|
||||
fn(item);
|
||||
|
Reference in New Issue
Block a user