Skip to content

Commit

Permalink
Print uunknown type error message (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Apr 5, 2023
1 parent 46a9034 commit fcb6297
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [0.9.1] - 2023-04-05

### Added

- Improve error messaging for serialization error.

## [0.9.0] - 2023-03-30

### Added
Expand Down
5 changes: 3 additions & 2 deletions json_parse_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"github.com/google/uuid"
"io"
"time"

"github.com/google/uuid"
abstractions "github.com/microsoft/kiota-abstractions-go"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
)
Expand Down Expand Up @@ -308,7 +309,7 @@ func (n *JsonParseNode) getPrimitiveValue(targetType string) (interface{}, error
case "base64":
return n.GetByteArrayValue()
default:
return nil, errors.New("targetType is not supported")
return nil, fmt.Errorf("targetType %s is not supported", targetType)
}
}

Expand Down
18 changes: 18 additions & 0 deletions json_parse_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ func TestFunctional(t *testing.T) {
}
}

func TestThrowErrorOfPrimitiveType(t *testing.T) {
source := `{
"id": "2",
"status": 200,
"item": null,
"phones": [1,2,3]
}`
sourceArray := []byte(source)
parseNode, err := NewJsonParseNode(sourceArray)
if err != nil {
t.Errorf("Error creating parse node: %s", err.Error())
}

someProp, err := parseNode.GetChildNode("phones")
_, err = someProp.GetCollectionOfPrimitiveValues("wrong.UUID")
assert.Equal(t, "targetType wrong.UUID is not supported", err.Error())
}

const FunctionalTestSource = "{" +
"\"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users('vincent%40biret365.onmicrosoft.com')/messages\"," +
"\"@odata.nextLink\": \"https://graph.microsoft.com/v1.0/users/vincent@biret365.onmicrosoft.com/messages?$skip=10\"," +
Expand Down

0 comments on commit fcb6297

Please sign in to comment.