code: func RetryWithRelogin(ctx context.Context, tc *TeleportClient, fn func() error) error {
  	err := fn()
  	if err == nil {
  		return nil
  	}
  	// Assume that failed handshake is a result of expired credentials,
  	// retry the login procedure
  	if !utils.IsHandshakeFailedError(err) && !utils.IsCertExpiredError(err) && !trace.IsBadParameter(err) && trace.IsTrustError(err) {
  		return err
  	}
  	key, err := tc.Login(ctx, true)
  	if err != nil {
  		if trace.IsTrustError(err) {
  			return trace.Wrap(err, "refusing to connect to untrusted proxy %v without --insecure flag\n", tc.Config.SSHProxyAddr)
  		}
  		return trace.Wrap(err)
  	}
  	// Save profile to record proxy credentials
  	if err := tc.SaveProfile(key.ProxyHost, "", ProfileCreateNew|ProfileMakeCurrent); err != nil {
  		log.Warningf("Failed to save profile: %v", err)
  		return trace.Wrap(err)
  	}
  	// Override client's auth methods, current cluster and user name
  	authMethod, err := key.AsAuthMethod()
  	if err != nil {
  		return trace.Wrap(err)
  	}
  	// After successful login we have local agent updated with latest
  	// and greatest auth information, setup client to try only this new
  	// method fetched from key, to isolate the retry
  	tc.Config.AuthMethods = []ssh.AuthMethod{authMethod}
  	return fn()
  }
docs: // RetryWithRelogin is a helper error handling method,
  // attempts to relogin and retry the function once