[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:
Jason Frerich
2022-08-05 05:12:01 -05:00
committed by GitHub
parent a0e1f2dbd6
commit 4dfb9fb60c
2 changed files with 16 additions and 3 deletions

View File

@@ -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: 'Cant find this server. Check spelling and URL format.',
intl: {
id: 'apps.error.network.no_server',
defaultMessage: 'Cant find this server. Check spelling and URL format.',
},
url: serverUrl,
});
}
return this.clients[serverUrl];
};