Skip to content

Commit 65ff4bf

Browse files
Merge pull request #7 from blackjune/patch-1
Return error from marshalling errors in response.go
2 parents 2fc21f5 + 5394aa9 commit 65ff4bf

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

request_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
. "github.com/smartystreets/goconvey/convey"
3131

3232
"github.com/northwesternmutual/grammes/gremconnect"
33+
"github.com/northwesternmutual/grammes/gremerror"
3334
)
3435

3536
func TestExecuteRequest(t *testing.T) {
@@ -158,7 +159,17 @@ func TestExecuteRequestErrorRetrievingResponse(t *testing.T) {
158159
jsonMarshalData = func(interface{}) ([]byte, error) { return nil, errors.New("ERROR") }
159160
Convey("Given a client that represents the Gremlin client", t, func() {
160161
dialer := &mockDialerStruct{}
161-
dialer.response = newVertexResponse
162+
dialer.response = `
163+
{
164+
"requestId": "61616161-6161-6161-2d61-6161612d6161",
165+
"status": {
166+
"message": "",
167+
"code": 597,
168+
"attributes": {}
169+
},
170+
"result":{"data":null,"meta":{"@type":"g:Map","@value":[]}}
171+
}
172+
`
162173
c, _ := Dial(dialer)
163174
Convey("When 'executeRequest' is called and retrieving the response throws an error", func() {
164175
bindings := make(map[string]string)
@@ -167,6 +178,10 @@ func TestExecuteRequestErrorRetrievingResponse(t *testing.T) {
167178
Convey("Then the error should be returned", func() {
168179
So(err, ShouldNotBeNil)
169180
})
181+
Convey("Then the error should be gremerror.NetworkError", func() {
182+
_, ok := err.(*gremerror.NetworkError)
183+
So(ok, ShouldBeTrue)
184+
})
170185
})
171186
})
172187
}

response.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ func (c *Client) retrieveResponse(id string) ([][]byte, error) {
7373

7474
if n := <-notifier.(chan int); n == 1 {
7575
if dataI, ok := c.results.Load(id); ok {
76-
7776
for _, d := range dataI.([]interface{}) {
77+
if err, ok = d.(error); ok {
78+
break
79+
}
7880
if dataPart, err = jsonMarshalData(d); err != nil {
79-
return nil, err
81+
break
8082
}
81-
8283
data = append(data, dataPart)
8384
}
84-
8585
close(notifier.(chan int))
8686
c.resultMessenger.Delete(id)
8787
c.deleteResponse(id)
8888
}
8989
}
9090

91-
return data, nil
91+
return data, err
9292
}
9393

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

0 commit comments

Comments
 (0)