Retry mechanism

更新时间:
复制 MD 格式

The V2.0 SDK automatically retries OpenAPI requests that fail due to network exceptions, improving service stability and reliability. The SDK does not retry requests that fail due to business logic errors, such as invalid parameters or a non-existent resource. Your application must handle these errors based on the specific error message.

Configuration methods

Note

The configuration priority is as follows, from highest to lowest: RuntimeOptions, then default configurations.

  • With the default configurations, the SDK does not retry failed requests. If you enable retries without specifying the number of attempts, the SDK retries a request up to three times.

  • Configure the retry mechanism by using runtime parameters (RuntimeOptions).

    import (
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    runtime := &util.RuntimeOptions{}
    // Enable the automatic retry mechanism.
    runtime.Autoretry = tea.Bool(true)
    // Set the maximum number of retries.
    runtime.MaxAttempts = tea.Int(3)