microsoftgraph / msgraph-sdk-go-core

Microsoft Graph SDK for Go - Core Library
https://learn.microsoft.com/graph/sdks/sdks-overview
MIT License
19 stars 9 forks source link

Customize retry Handler Middleware #312

Open ritu-rubrik opened 2 months ago

ritu-rubrik commented 2 months ago

Currently while using middlewate I use this code to get the default lit of middlewares. defaultClientOptions := msgraph.GetDefaultClientOptions() defaultMiddleWare := msgraphgocore.GetDefaultMiddlewaresWithOptions(&defaultClientOptions)

However, I am not sure how to override the Retry handler alone in this list of middlewares.

Looking for an example to do this/

rkodev commented 1 month ago

Hi @ritu-rubrik, thanks for trying out the SDK. If you would like to override the Retry handler, you are able to do it when executing the command i.e here is an example. You will only need to provide the retry option in the request configuration

    retryHandlerOptions := nethttplibrary.RetryHandlerOptions{
        ShouldRetry: func(delay time.Duration, executionCount int, request *http.Request, response *http.Response) bool {
            return false
        },
    }

    opts := applications.ApplicationsRequestBuilderGetRequestConfiguration{
        QueryParameters: &applications.ApplicationsRequestBuilderGetQueryParameters{
            Select: []string{"displayName", "appId", "id", "keyCredentials", "passwordCredentials"},
            Top:    to.Ptr[int32](100),
        },
        Options: []abstractions.RequestOption{&retryHandlerOptions},
    }