override async execute()

in common/lib/plugins/failover2/failover2_plugin.ts [200:228]


  override async execute<T>(methodName: string, methodFunc: () => Promise<T>): Promise<T> {
    // Verify there weren't any unexpected errors emitted while the connection was idle.
    if (this.pluginService.hasNetworkError()) {
      // Throw the unexpected error directly to be handled.
      throw this.pluginService.getUnexpectedError();
    }

    if (!this.enableFailoverSetting || this.canDirectExecute(methodName)) {
      return await methodFunc();
    }

    let result: T = null;
    try {
      result = await methodFunc();
    } catch (error) {
      logger.debug(Messages.get("Failover.detectedError", error.message));
      if (this._lastError !== error && this.shouldErrorTriggerClientSwitch(error)) {
        await this.invalidateCurrentClient();
        const currentHostInfo: HostInfo = this.pluginService.getCurrentHostInfo();
        if (currentHostInfo !== null) {
          this.pluginService.setAvailability(currentHostInfo.allAliases ?? new Set(), HostAvailability.NOT_AVAILABLE);
        }
        await this.failover();
        this._lastError = error;
      }
      throw error;
    }
    return result;
  }