override async execute()

in common/lib/plugins/failover/failover_plugin.ts [282:314]


  override async execute<T>(methodName: string, methodFunc: () => Promise<T>): Promise<T> {
    try {
      // Verify there aren't any unexpected error 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();
      }

      if (this.canUpdateTopology(methodName)) {
        await this.updateTopology(false);
      }

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

        this._lastError = e;
        await this.pickNewConnection();
      }

      throw e;
    }
  }