[IMPROVEMENT] Error messages on connect (#1379)

This commit is contained in:
Djorkaeff Alexandre 2019-11-13 16:52:00 -03:00 committed by Diego Mello
parent edf73124bb
commit 1b2833107f
4 changed files with 67 additions and 8 deletions

View File

@ -136,6 +136,7 @@ export default {
connecting_server: 'connecting to server', connecting_server: 'connecting to server',
Connecting: 'Connecting...', Connecting: 'Connecting...',
Contact_us: 'Contact us', Contact_us: 'Contact us',
Contact_your_server_admin: 'Contact your server admin.',
Continue_with: 'Continue with', Continue_with: 'Continue with',
Copied_to_clipboard: 'Copied to clipboard!', Copied_to_clipboard: 'Copied to clipboard!',
Copy: 'Copy', Copy: 'Copy',
@ -257,6 +258,7 @@ export default {
No_Reactions: 'No Reactions', No_Reactions: 'No Reactions',
No_Read_Receipts: 'No Read Receipts', No_Read_Receipts: 'No Read Receipts',
Not_logged: 'Not logged', Not_logged: 'Not logged',
Not_RC_Server: 'This is not a Rocket.Chat server.\n{{contact}}',
Nothing: 'Nothing', Nothing: 'Nothing',
Nothing_to_save: 'Nothing to save!', Nothing_to_save: 'Nothing to save!',
Notify_active_in_this_room: 'Notify active users in this room', Notify_active_in_this_room: 'Notify active users in this room',
@ -375,7 +377,7 @@ export default {
Tap_to_view_servers_list: 'Tap to view servers list', Tap_to_view_servers_list: 'Tap to view servers list',
Terms_of_Service: ' Terms of Service ', Terms_of_Service: ' Terms of Service ',
Theme: 'Theme', Theme: 'Theme',
The_URL_is_invalid: 'The URL you entered is invalid. Check it and try again, please!', The_URL_is_invalid: 'Invalid URL or unable to establish a secure connection.\n{{contact}}',
There_was_an_error_while_action: 'There was an error while {{action}}!', There_was_an_error_while_action: 'There was an error while {{action}}!',
This_room_is_blocked: 'This room is blocked', This_room_is_blocked: 'This room is blocked',
This_room_is_read_only: 'This room is read only', This_room_is_read_only: 'This room is read only',
@ -420,6 +422,7 @@ export default {
Video_call: 'Video call', Video_call: 'Video call',
View_Original: 'View Original', View_Original: 'View Original',
Voice_call: 'Voice call', Voice_call: 'Voice call',
Websocket_disabled: 'Websocket is disabled for this server.\n{{contact}}',
Welcome: 'Welcome', Welcome: 'Welcome',
Welcome_to_RocketChat: 'Welcome to Rocket.Chat', Welcome_to_RocketChat: 'Welcome to Rocket.Chat',
Whats_your_2fa: 'What\'s your 2FA code?', Whats_your_2fa: 'What\'s your 2FA code?',

View File

@ -138,6 +138,7 @@ export default {
connecting_server: 'conectando no servidor', connecting_server: 'conectando no servidor',
Connecting: 'Conectando...', Connecting: 'Conectando...',
Continue_with: 'Entrar com', Continue_with: 'Entrar com',
Contact_your_server_admin: 'Contate o administrador do servidor.',
Copied_to_clipboard: 'Copiado para a área de transferência!', Copied_to_clipboard: 'Copiado para a área de transferência!',
Copy: 'Copiar', Copy: 'Copiar',
Permalink: 'Link-Permanente', Permalink: 'Link-Permanente',
@ -242,6 +243,7 @@ export default {
Nothing_to_save: 'Nada para salvar!', Nothing_to_save: 'Nada para salvar!',
Notify_active_in_this_room: 'Notificar usuários ativos nesta sala', Notify_active_in_this_room: 'Notificar usuários ativos nesta sala',
Notify_all_in_this_room: 'Notificar todos nesta sala', Notify_all_in_this_room: 'Notificar todos nesta sala',
Not_RC_Server: 'Este não é um servidor Rocket.Chat.\n{{contact}}',
Offline: 'Offline', Offline: 'Offline',
Oops: 'Ops!', Oops: 'Ops!',
Online: 'Online', Online: 'Online',
@ -334,7 +336,7 @@ export default {
Take_a_photo: 'Tirar uma foto', Take_a_photo: 'Tirar uma foto',
Take_a_video: 'Gravar um vídeo', Take_a_video: 'Gravar um vídeo',
Terms_of_Service: ' Termos de Serviço ', Terms_of_Service: ' Termos de Serviço ',
The_URL_is_invalid: 'A URL fornecida é inválida ou não acessível. Por favor tente novamente, mas com uma url diferente.', The_URL_is_invalid: 'A URL fornecida é inválida ou incapaz de estabelecer uma conexão segura.\n{{contact}}',
There_was_an_error_while_action: 'Aconteceu um erro {{action}}!', There_was_an_error_while_action: 'Aconteceu um erro {{action}}!',
This_room_is_blocked: 'Este quarto está bloqueado', This_room_is_blocked: 'Este quarto está bloqueado',
This_room_is_read_only: 'Este quarto é apenas de leitura', This_room_is_read_only: 'Este quarto é apenas de leitura',
@ -375,6 +377,7 @@ export default {
Username_or_email: 'Usuário ou email', Username_or_email: 'Usuário ou email',
Video_call: 'Chamada de vídeo', Video_call: 'Chamada de vídeo',
Voice_call: 'Chamada de voz', Voice_call: 'Chamada de voz',
Websocket_disabled: 'Websocket está desativado para esse servidor.\n{{contact}}',
Welcome: 'Bem vindo', Welcome: 'Bem vindo',
Welcome_to_RocketChat: 'Bem vindo ao Rocket.Chat', Welcome_to_RocketChat: 'Bem vindo ao Rocket.Chat',
Whats_your_2fa: 'Qual seu código de autenticação?', Whats_your_2fa: 'Qual seu código de autenticação?',

View File

@ -48,6 +48,7 @@ import callJitsi from './methods/callJitsi';
import { getDeviceToken } from '../notifications/push'; import { getDeviceToken } from '../notifications/push';
import { SERVERS, SERVER_URL } from '../constants/userDefaults'; import { SERVERS, SERVER_URL } from '../constants/userDefaults';
import { setActiveUsers } from '../actions/activeUsers'; import { setActiveUsers } from '../actions/activeUsers';
import I18n from '../i18n';
const TOKEN_KEY = 'reactnativemeteor_usertoken'; const TOKEN_KEY = 'reactnativemeteor_usertoken';
const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY'; const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY';
@ -88,9 +89,53 @@ const RocketChat = {
console.warn(`RNUserDefaults error: ${ error.message }`); console.warn(`RNUserDefaults error: ${ error.message }`);
} }
}, },
async getServerInfo(server) { async getWebsocketInfo({ server }) {
// Use useSsl: false only if server url starts with http://
const useSsl = !/http:\/\//.test(server);
const sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl });
try { try {
const result = await fetch(`${ server }/api/info`).then(response => response.json()); await sdk.connect();
} catch (err) {
if (err.message && err.message.includes('400')) {
return {
success: false,
message: 'Websocket_disabled',
messageOptions: {
contact: I18n.t('Contact_your_server_admin')
}
};
}
}
sdk.disconnect();
return {
success: true
};
},
async getServerInfo(server) {
const notRCServer = {
success: false,
message: 'Not_RC_Server',
messageOptions: {
contact: I18n.t('Contact_your_server_admin')
}
};
try {
const result = await fetch(`${ server }/api/info`).then(async(response) => {
let res = notRCServer;
try {
res = await response.json();
if (!(res && res.success)) {
return notRCServer;
}
} catch (e) {
// do nothing
}
return res;
});
if (result.success) { if (result.success) {
if (semver.lt(result.version, MIN_ROCKETCHAT_VERSION)) { if (semver.lt(result.version, MIN_ROCKETCHAT_VERSION)) {
return { return {
@ -102,14 +147,17 @@ const RocketChat = {
} }
}; };
} }
return result;
} }
return result;
} catch (e) { } catch (e) {
log(e); log(e);
} }
return { return {
success: false, success: false,
message: 'The_URL_is_invalid' message: 'The_URL_is_invalid',
messageOptions: {
contact: I18n.t('Contact_your_server_admin')
}
}; };
}, },
stopListener(listener) { stopListener(listener) {

View File

@ -22,9 +22,14 @@ import { SERVERS, TOKEN, SERVER_URL } from '../constants/userDefaults';
const getServerInfo = function* getServerInfo({ server, raiseError = true }) { const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
try { try {
const serverInfo = yield RocketChat.getServerInfo(server); const serverInfo = yield RocketChat.getServerInfo(server);
if (!serverInfo.success) { let websocketInfo = true;
if (raiseError) { if (raiseError) {
Alert.alert(I18n.t('Oops'), I18n.t(serverInfo.message, serverInfo.messageOptions)); websocketInfo = yield RocketChat.getWebsocketInfo({ server });
}
if (!serverInfo.success || !websocketInfo.success) {
if (raiseError) {
const info = serverInfo.success ? websocketInfo : serverInfo;
Alert.alert(I18n.t('Oops'), I18n.t(info.message, info.messageOptions));
} }
yield put(serverFailure()); yield put(serverFailure());
return; return;