Skip to content

Commit

Permalink
Merge pull request #7 from blackjune/patch-1
Browse files Browse the repository at this point in the history
Return error from marshalling errors in response.go
  • Loading branch information
damienstamates committed Nov 12, 2019
2 parents 2fc21f5 + 5394aa9 commit 65ff4bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 16 additions & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
. "github.com/smartystreets/goconvey/convey"

"github.com/northwesternmutual/grammes/gremconnect"
"github.com/northwesternmutual/grammes/gremerror"
)

func TestExecuteRequest(t *testing.T) {
Expand Down Expand Up @@ -158,7 +159,17 @@ func TestExecuteRequestErrorRetrievingResponse(t *testing.T) {
jsonMarshalData = func(interface{}) ([]byte, error) { return nil, errors.New("ERROR") }
Convey("Given a client that represents the Gremlin client", t, func() {
dialer := &mockDialerStruct{}
dialer.response = newVertexResponse
dialer.response = `
{
"requestId": "61616161-6161-6161-2d61-6161612d6161",
"status": {
"message": "",
"code": 597,
"attributes": {}
},
"result":{"data":null,"meta":{"@type":"g:Map","@value":[]}}
}
`
c, _ := Dial(dialer)
Convey("When 'executeRequest' is called and retrieving the response throws an error", func() {
bindings := make(map[string]string)
Expand All @@ -167,6 +178,10 @@ func TestExecuteRequestErrorRetrievingResponse(t *testing.T) {
Convey("Then the error should be returned", func() {
So(err, ShouldNotBeNil)
})
Convey("Then the error should be gremerror.NetworkError", func() {
_, ok := err.(*gremerror.NetworkError)
So(ok, ShouldBeTrue)
})
})
})
}
Expand Down
10 changes: 5 additions & 5 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ func (c *Client) retrieveResponse(id string) ([][]byte, error) {

if n := <-notifier.(chan int); n == 1 {
if dataI, ok := c.results.Load(id); ok {

for _, d := range dataI.([]interface{}) {
if err, ok = d.(error); ok {
break
}
if dataPart, err = jsonMarshalData(d); err != nil {
return nil, err
break
}

data = append(data, dataPart)
}

close(notifier.(chan int))
c.resultMessenger.Delete(id)
c.deleteResponse(id)
}
}

return data, nil
return data, err
}

// deleteRespones deletes the response from the container. Used for cleanup purposes by requester.
Expand Down

0 comments on commit 65ff4bf

Please sign in to comment.