Skip to content

Commit

Permalink
Merge branch 'main' into fix/context-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Jan 22, 2024
2 parents 08a3d95 + 9475b23 commit 2453888
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.2.0] - 2023-01-22
## [1.2.1] - 2023-01-22

### Changed

- Fix bug passing no timeout in client as 0 timeout in context .

## [1.2.0] - 2024-01-22

### Added

- Adds support for XXX status code.

## [1.1.2] - 2024-01-20

### Changed

- Changed the code by replacing ioutil.ReadAll and ioutil.NopCloser with io.ReadAll and io.NopCloser, respectively, due to their deprecation.

- Changed the code by replacing ioutil.ReadAll and ioutil.NopCloser with io.ReadAll and io.NopCloser, respectively, due to their deprecation.

## [1.1.1] - 2023-11-22

Expand Down
6 changes: 6 additions & 0 deletions internal/mock_parse_node_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (e *MockParseNode) GetCollectionOfEnumValues(parser absser.EnumFactory) ([]
return nil, nil
}
func (e *MockParseNode) GetObjectValue(ctor absser.ParsableFactory) (absser.Parsable, error) {
if ctor != nil {
_, err := ctor(e)
if err != nil {
return nil, err
}
}
return &MockEntity{}, nil
}
func (e *MockParseNode) GetStringValue() (*string, error) {
Expand Down
2 changes: 2 additions & 0 deletions nethttp_request_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ func (a *NetHttpRequestAdapter) throwIfFailedResponse(ctx context.Context, respo
errorCtor = errorMappings["4XX"]
} else if response.StatusCode >= 500 && response.StatusCode < 600 && errorMappings["5XX"] != nil {
errorCtor = errorMappings["5XX"]
} else if errorMappings["XXX"] != nil && response.StatusCode >= 400 && response.StatusCode < 600 {
errorCtor = errorMappings["XXX"]
}
}

Expand Down
35 changes: 35 additions & 0 deletions nethttp_request_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nethttplibrary

import (
"context"
"github.com/microsoft/kiota-abstractions-go/serialization"
nethttp "net/http"
httptest "net/http/httptest"
"net/url"
Expand Down Expand Up @@ -75,6 +76,40 @@ func TestItThrowsApiError(t *testing.T) {
assert.Equal(t, "example-guid", apiError.ResponseHeaders.Get("client-request-id")[0])
}

func TestGenericError(t *testing.T) {
testServer := httptest.NewServer(nethttp.HandlerFunc(func(res nethttp.ResponseWriter, req *nethttp.Request) {
res.WriteHeader(500)
res.Write([]byte("test"))
}))
defer func() { testServer.Close() }()
authProvider := &absauth.AnonymousAuthenticationProvider{}
adapter, err := NewNetHttpRequestAdapterWithParseNodeFactory(authProvider, &internal.MockParseNodeFactory{})
assert.Nil(t, err)
assert.NotNil(t, adapter)

uri, err := url.Parse(testServer.URL)
assert.Nil(t, err)
assert.NotNil(t, uri)
request := abs.NewRequestInformation()
request.SetUri(*uri)
request.Method = abs.GET

result := 0
errorMapping := abs.ErrorMappings{
"XXX": func(parseNode serialization.ParseNode) (serialization.Parsable, error) {
result++
return nil, &abs.ApiError{
Message: "test XXX message",
}
},
}

_, err2 := adapter.SendPrimitive(context.TODO(), request, "[]byte", errorMapping)
assert.NotNil(t, err2)
assert.Equal(t, 1, result)
assert.Equal(t, "test XXX message", err2.Error())
}

func TestImplementationHonoursInterface(t *testing.T) {
authProvider := &absauth.AnonymousAuthenticationProvider{}
adapter, err := NewNetHttpRequestAdapter(authProvider)
Expand Down

0 comments on commit 2453888

Please sign in to comment.