Skip to content

Commit

Permalink
Checking for SOAP faults
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpoer committed Jun 5, 2019
1 parent 3647e43 commit fa73331
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
22 changes: 18 additions & 4 deletions gocvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
14 changes: 14 additions & 0 deletions gocvent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions samples/Fault.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<soap:Fault>
<faultcode xmlns:q0="http://schemas.cvent.com/api/2006-11">q0:CV10001</faultcode>
<faultstring>INVALID_SOAP_REQUEST</faultstring>
<faultactor>http://api.cvent.com/soap/V200611.ASMX</faultactor>
<detail>
<Main-Exception xmlns="http://schemas.cvent.com/api/2006-11">
<Exception-Detail />
</Main-Exception>
<Secondary-Exception t:has-more="yes"
xmlns:t="http://schemas.cvent.com/api/2006-11"
xmlns="http://schemas.cvent.com/api/2006-11" />
</detail>
</soap:Fault>

0 comments on commit fa73331

Please sign in to comment.