diff --git a/gocvent.go b/gocvent.go index aab33b6..329d6c5 100644 --- a/gocvent.go +++ b/gocvent.go @@ -28,7 +28,11 @@ func (c *CventAPI) Auth(accountNumber string, user string, pass string) (bool, e } var r LoginResponse - c.soap.Unmarshal(&r) + err = c.soap.Unmarshal(&r) + if err != nil { + return false, errors.New("CventAPI.Auth received SOAP Fault: " + err.Error()) + } + if r.LoginResult.LoginSuccess != "true" { return false, errors.New("CventAPI.Auth Login Failure: " + r.LoginResult.ErrorMessage) } @@ -60,7 +64,10 @@ func (c *CventAPI) DescribeCvObject(objectTypes []string) ([]DescribeCvObjectRes return r.DescribeCvObjectResults, errors.New("CventAPI.DescribeCvObject Soap DescribeCvObject Failure: " + err.Error()) } - c.soap.Unmarshal(&r) + err = c.soap.Unmarshal(&r) + if err != nil { + return r.DescribeCvObjectResults, errors.New("CventAPI.DescribeCvObject received SOAP Fault: " + err.Error()) + } return r.DescribeCvObjectResults, nil } @@ -74,7 +81,11 @@ func (c *CventAPI) DescribeGlobal() (DescribeGlobalResult, error) { return r.DescribeGlobalResult, errors.New("CventAPI.DescribeGlobal Soap DescribeGlobal Failure: " + err.Error()) } - c.soap.Unmarshal(&r) + err = c.soap.Unmarshal(&r) + if err != nil { + return r.DescribeGlobalResult, errors.New("CventAPI.DescribeGlobal received SOAP Fault: " + err.Error()) + } + return r.DescribeGlobalResult, nil } @@ -93,6 +104,9 @@ func (c *CventAPI) Search(ObjectType string, Filters []Filter) (SearchResult, er return r.SearchResult, errors.New("CventAPI.Search Soap Search Failure: " + err.Error()) } - c.soap.Unmarshal(&r) + err = c.soap.Unmarshal(&r) + if err != nil { + return r.SearchResult, errors.New("CventAPI.Search received SOAP Fault: " + err.Error()) + } return r.SearchResult, nil } diff --git a/gocvent_test.go b/gocvent_test.go index 465553a..efbe687 100644 --- a/gocvent_test.go +++ b/gocvent_test.go @@ -135,6 +135,20 @@ func TestDescribeCvObjectSingle(t *testing.T) { assert.True(t, foundCompanyField, "Could not find Company field on the Contact Object") } +func TestDescribeCvObjectSingleBadObject(t *testing.T) { + cvent, success, err := genericAuth() + if err != nil || !success { + t.Errorf("TestDescribeCvObjectSingleBadObject fails because authorization or invocation failed") + return + } + + var objectList = make([]string, 1) + objectList[0] = "SomeFakeObjectName" + + r, err := cvent.DescribeCvObject(objectList) + assert.NotEmpty(t, err) + assert.Zero(t, len(r)) +} func TestDescribeGlobal(t *testing.T) { cvent, success, err := genericAuth() if err != nil || !success { diff --git a/samples/Fault.xml b/samples/Fault.xml new file mode 100644 index 0000000..84d2bd1 --- /dev/null +++ b/samples/Fault.xml @@ -0,0 +1,13 @@ + + q0:CV10001 + INVALID_SOAP_REQUEST + http://api.cvent.com/soap/V200611.ASMX + + + + + + + \ No newline at end of file