diff --git a/request_test.go b/request_test.go index 4e03e68..3675fdd 100644 --- a/request_test.go +++ b/request_test.go @@ -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) { @@ -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) @@ -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) + }) }) }) } diff --git a/response.go b/response.go index 81a4fc0..e12c6a8 100644 --- a/response.go +++ b/response.go @@ -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.