microsoftgraph / msgraph-sdk-go-core

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

GetBatchResponseById doesn't pass type name to `throwErrors` #248

Closed eric-millin closed 10 months ago

eric-millin commented 1 year ago

You can see when using a debugger to step through this code

func TestGetResponseByIdFailedRequest(t *testing.T) {
    errorMapping := abstractions.ErrorMappings{
        "4XX": internal.CreateSampleErrorFromDiscriminatorValue,
        "5XX": internal.CreateSampleErrorFromDiscriminatorValue,
    }
    err := RegisterError("Userable", errorMapping)
    require.NoError(t, err)

    mockServer := makeMockRequest(200, getDummyJSON())
    defer mockServer.Close()

    mockPath := mockServer.URL + "/$batch"
    reqAdapter.SetBaseUrl(mockPath)

    reqInfo := getRequestInfo()
    batch := NewBatchRequest(reqAdapter)
    _, err = batch.AddBatchRequestStep(*reqInfo)
    require.NoError(t, err)

    resp, err := batch.Send(context.Background(), reqAdapter)
    require.NoError(t, err)
}

Change the following line: https://github.com/microsoftgraph/msgraph-sdk-go-core/blob/main/batch_requests.go#L269 to

        return res, throwErrors(item, reflect.TypeOf(new(T)).Elem().Name())

and you'll see that the error factories are returned.