async onApplyServerUrlChange()

in src/views/enter-server/enter-server.tsx [96:134]


  async onApplyServerUrlChange(): Promise<string | null | undefined> {
    if (!this.isValidInput()) {
      return;
    }

    this.setState({
      connecting: true,
      error: null,
    });
    const trimmedUrl = this.state.serverUrl.trim().replace(/\/$/i, '');
    const urlsToTry = this.getPossibleUrls(trimmedUrl);
    log.log(
      `Entered: "${this.state.serverUrl}", will try that urls: ${urlsToTry.join(
        ', ',
      )}`,
    );
    let errorToShow: AnyError | null = null;

    for (const url of urlsToTry) {
      log.log(`Trying: "${url}"`);

      try {
        await this.props?.connectToYoutrack?.(url);
        log.log(`Successfully connected to ${url}`);
        return;
      } catch (error) {
        log.log(`Failed to connect to ${url}`, error);
        log.log(`Connection error for ${url}: ${error && error.toString()}`);
        errorToShow = (errorToShow || error) as AnyError;
      }
    }

    const errorMessage = errorToShow ? await resolveErrorMessage(errorToShow) : null;
    this.setState({
      error: errorMessage,
      connecting: false,
    });
    return errorMessage;
  }