[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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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];
};

View file

@ -46,6 +46,7 @@
"apps.error.form.submit.pretext": "There has been an error submitting the modal. Contact the app developer. Details: {details}",
"apps.error.lookup.error_preparing_request": "Error preparing lookup request: {errorMessage}",
"apps.error.malformed_binding": "This binding is not properly formed. Contact the App developer.",
"apps.error.network.no_server": "Cant find this server. Check spelling and URL format.",
"apps.error.parser": "Parsing error: {error}",
"apps.error.parser.empty_value": "Empty values are not allowed.",
"apps.error.parser.execute_non_leaf": "You must select a subcommand.",