Merge pull request #2276 from mattermost/PLT-2030

PLT-2030 fixing error handling
Этот коммит содержится в:
Christopher Speller
2016-03-01 08:27:57 -05:00
родитель 39c83f70fc 6c18e13f8a
Коммит a66e9513ad
7 изменённых файлов: 58 добавлений и 42 удалений

Просмотреть файл

@@ -6,6 +6,7 @@
AsyncClient with requests. */ AsyncClient with requests. */
import * as AsyncClient from '../utils/async_client.jsx'; import * as AsyncClient from '../utils/async_client.jsx';
import * as Client from '../utils/client.jsx';
import SocketStore from '../stores/socket_store.jsx'; import SocketStore from '../stores/socket_store.jsx';
import ChannelStore from '../stores/channel_store.jsx'; import ChannelStore from '../stores/channel_store.jsx';
import PostStore from '../stores/post_store.jsx'; import PostStore from '../stores/post_store.jsx';
@@ -45,6 +46,14 @@ const holders = defineMessages({
wrote: { wrote: {
id: 'channel_loader.wrote', id: 'channel_loader.wrote',
defaultMessage: ' wrote: ' defaultMessage: ' wrote: '
},
connectionError: {
id: 'channel_loader.connection_error',
defaultMessage: 'There appears to be a problem with your internet connection.'
},
unknownError: {
id: 'channel_loader.unknown_error',
defaultMessage: 'We received an unexpected status code from the server.'
} }
}); });
@@ -67,6 +76,11 @@ class ChannelLoader extends React.Component {
wrote: formatMessage(holders.wrote) wrote: formatMessage(holders.wrote)
}); });
Client.setTranslations({
connectionError: formatMessage(holders.connectionError),
unknownError: formatMessage(holders.unknownError)
});
this.state = {}; this.state = {};
} }
componentDidMount() { componentDidMount() {

Просмотреть файл

@@ -38,25 +38,9 @@ export default class ErrorBar extends React.Component {
return false; return false;
} }
if (s.connErrorCount && s.connErrorCount >= 1 && s.connErrorCount < 7) {
return false;
}
return true; return true;
} }
isConnectionError(s) {
if (!s.connErrorCount || s.connErrorCount === 0) {
return false;
}
if (s.connErrorCount > 7) {
return true;
}
return false;
}
componentWillMount() { componentWillMount() {
if (global.window.mm_config.SendEmailNotifications === 'false') { if (global.window.mm_config.SendEmailNotifications === 'false') {
ErrorStore.storeLastError({message: this.props.intl.formatMessage(messages.preview)}); ErrorStore.storeLastError({message: this.props.intl.formatMessage(messages.preview)});

Просмотреть файл

@@ -59,9 +59,9 @@ export default class Textbox extends React.Component {
} }
onRecievedError() { onRecievedError() {
const errorState = ErrorStore.getLastError(); const errorCount = ErrorStore.getConnectionErrorCount();
if (errorState && errorState.connErrorCount > 0) { if (errorCount > 0) {
this.setState({connection: 'bad-connection'}); this.setState({connection: 'bad-connection'});
} else { } else {
this.setState({connection: ''}); this.setState({connection: ''});

Просмотреть файл

@@ -18,7 +18,6 @@ class ErrorStoreClass extends EventEmitter {
this.emitChange = this.emitChange.bind(this); this.emitChange = this.emitChange.bind(this);
this.addChangeListener = this.addChangeListener.bind(this); this.addChangeListener = this.addChangeListener.bind(this);
this.removeChangeListener = this.removeChangeListener.bind(this); this.removeChangeListener = this.removeChangeListener.bind(this);
this.handledError = this.handledError.bind(this);
this.getLastError = this.getLastError.bind(this); this.getLastError = this.getLastError.bind(this);
this.storeLastError = this.storeLastError.bind(this); this.storeLastError = this.storeLastError.bind(this);
} }
@@ -35,10 +34,6 @@ class ErrorStoreClass extends EventEmitter {
this.removeListener(CHANGE_EVENT, callback); this.removeListener(CHANGE_EVENT, callback);
} }
handledError() {
BrowserStore.removeItem('last_error');
}
getLastError() { getLastError() {
return BrowserStore.getItem('last_error'); return BrowserStore.getItem('last_error');
} }
@@ -47,8 +42,23 @@ class ErrorStoreClass extends EventEmitter {
BrowserStore.setItem('last_error', error); BrowserStore.setItem('last_error', error);
} }
getConnectionErrorCount() {
var count = BrowserStore.getItem('last_error_conn');
if (count == null) {
return 0;
}
return count;
}
setConnectionErrorCount(count) {
BrowserStore.setItem('last_error_conn', count);
}
clearLastError() { clearLastError() {
BrowserStore.removeItem('last_error'); BrowserStore.removeItem('last_error');
BrowserStore.removeItem('last_error_conn');
} }
} }

Просмотреть файл

@@ -58,6 +58,10 @@ class SocketStoreClass extends EventEmitter {
if (this.failCount === 0) { if (this.failCount === 0) {
console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console
if (ErrorStore.getConnectionErrorCount() > 0) {
ErrorStore.setConnectionErrorCount(0);
ErrorStore.emitChange();
}
} }
conn = new WebSocket(connUrl); conn = new WebSocket(connUrl);
@@ -65,10 +69,8 @@ class SocketStoreClass extends EventEmitter {
if (this.failCount > 0) { if (this.failCount > 0) {
console.log('websocket re-established connection'); //eslint-disable-line no-console console.log('websocket re-established connection'); //eslint-disable-line no-console
if (ErrorStore.getLastError()) { ErrorStore.clearLastError();
ErrorStore.storeLastError(null); ErrorStore.emitChange();
ErrorStore.emitChange();
}
AsyncClient.getChannels(); AsyncClient.getChannels();
AsyncClient.getPosts(ChannelStore.getCurrentId()); AsyncClient.getPosts(ChannelStore.getCurrentId());
@@ -86,7 +88,11 @@ class SocketStoreClass extends EventEmitter {
this.failCount = this.failCount + 1; this.failCount = this.failCount + 1;
ErrorStore.storeLastError({connErrorCount: this.failCount, message: this.translations.socketError}); if (this.failCount > 7) {
ErrorStore.storeLastError({message: this.translations.socketError});
}
ErrorStore.setConnectionErrorCount(this.failCount);
ErrorStore.emitChange(); ErrorStore.emitChange();
setTimeout( setTimeout(

Просмотреть файл

@@ -4,6 +4,15 @@ import BrowserStore from '../stores/browser_store.jsx';
import TeamStore from '../stores/team_store.jsx'; import TeamStore from '../stores/team_store.jsx';
import ErrorStore from '../stores/error_store.jsx'; import ErrorStore from '../stores/error_store.jsx';
let translations = {
connectionError: 'There appears to be a problem with your internet connection.',
unknownError: 'We received an unexpected status code from the server.'
};
export function setTranslations(messages) {
translations = messages;
}
export function track(category, action, label, property, value) { export function track(category, action, label, property, value) {
global.window.analytics.track(action, {category, label, property, value}); global.window.analytics.track(action, {category, label, property, value});
} }
@@ -23,23 +32,14 @@ function handleError(methodName, xhr, status, err) {
var msg = ''; var msg = '';
if (e) { if (e) {
msg = 'error in ' + methodName + ' msg=' + e.message + ' detail=' + e.detailed_error + ' rid=' + e.request_id; msg = 'method=' + methodName + ' msg=' + e.message + ' detail=' + e.detailed_error + ' rid=' + e.request_id;
} else { } else {
msg = 'error in ' + methodName + ' status=' + status + ' statusCode=' + xhr.status + ' err=' + err; msg = 'method=' + methodName + ' status=' + status + ' statusCode=' + xhr.status + ' err=' + err;
if (xhr.status === 0) { if (xhr.status === 0) {
let errorCount = 1; e = {message: translations.connectionError};
const oldError = ErrorStore.getLastError();
let connectError = 'There appears to be a problem with your internet connection';
if (oldError && oldError.connErrorCount) {
errorCount += oldError.connErrorCount;
connectError = 'Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.';
}
e = {message: connectError, connErrorCount: errorCount};
} else { } else {
e = {message: 'We received an unexpected status code from the server (' + xhr.status + ')'}; e = {message: translations.unknownError + ' (' + xhr.status + ')'};
} }
} }
@@ -279,7 +279,7 @@ export function logout() {
var currentTeamUrl = TeamStore.getCurrentTeamUrl(); var currentTeamUrl = TeamStore.getCurrentTeamUrl();
BrowserStore.signalLogout(); BrowserStore.signalLogout();
BrowserStore.clear(); BrowserStore.clear();
ErrorStore.storeLastError(null); ErrorStore.clearLastError();
window.location.href = currentTeamUrl + '/logout'; window.location.href = currentTeamUrl + '/logout';
} }

Просмотреть файл

@@ -543,6 +543,8 @@
"channel_loader.uploadedFile": " uploaded a file", "channel_loader.uploadedFile": " uploaded a file",
"channel_loader.uploadedImage": " uploaded an image", "channel_loader.uploadedImage": " uploaded an image",
"channel_loader.wrote": " wrote: ", "channel_loader.wrote": " wrote: ",
"channel_loader.connection_error": "There appears to be a problem with your internet connection.",
"channel_loader.unknown_error": "We received an unexpected status code from the server.",
"channel_members_modal.addNew": " Add New Members", "channel_members_modal.addNew": " Add New Members",
"channel_members_modal.close": "Close", "channel_members_modal.close": "Close",
"channel_memebers_modal.members": " Members", "channel_memebers_modal.members": " Members",