forked from Ivasoft/mattermost-mobile
[Gekidou MM-45178] Improve wording about url not being a valid one (#6449)
* if the API client returns and error, throw a new error with better descriptive text for the user * add intl to message * move happy path code into try block
This commit is contained in:
@@ -14,6 +14,7 @@ import UserAgent from 'react-native-user-agent';
|
||||
import LocalConfig from '@assets/config.json';
|
||||
import {Client} from '@client/rest';
|
||||
import * as ClientConstants from '@client/rest/constants';
|
||||
import ClientError from '@client/rest/error';
|
||||
import {CERTIFICATE_ERRORS} from '@constants/network';
|
||||
import ManagedApp from '@init/managed_app';
|
||||
import {logError} from '@utils/log';
|
||||
@@ -77,9 +78,20 @@ class NetworkManager {
|
||||
|
||||
public createClient = async (serverUrl: string, bearerToken?: string) => {
|
||||
const config = await this.buildConfig();
|
||||
const {client} = await getOrCreateAPIClient(serverUrl, config, this.clientErrorEventHandler);
|
||||
const csrfToken = await getCSRFFromCookie(serverUrl);
|
||||
this.clients[serverUrl] = new Client(client, serverUrl, bearerToken, csrfToken);
|
||||
try {
|
||||
const {client} = await getOrCreateAPIClient(serverUrl, config, this.clientErrorEventHandler);
|
||||
const csrfToken = await getCSRFFromCookie(serverUrl);
|
||||
this.clients[serverUrl] = new Client(client, serverUrl, bearerToken, csrfToken);
|
||||
} catch (error) {
|
||||
throw new ClientError(serverUrl, {
|
||||
message: 'Can’t find this server. Check spelling and URL format.',
|
||||
intl: {
|
||||
id: 'apps.error.network.no_server',
|
||||
defaultMessage: 'Can’t find this server. Check spelling and URL format.',
|
||||
},
|
||||
url: serverUrl,
|
||||
});
|
||||
}
|
||||
|
||||
return this.clients[serverUrl];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user