Update error handling

This commit is contained in:
Steven Polley 2018-07-22 01:22:22 -06:00
parent 09e6dea75a
commit 3440d00924
2 changed files with 11 additions and 6 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
example/main.go

View File

@ -38,17 +38,19 @@ type OrganizationList struct {
//GetOrganizationByID expects an ITG organization ID
//Returns a pointer to an Organization struct
func (itg *ITGAPI) GetOrganizationByID(organizationID int) *Organization {
func (itg *ITGAPI) GetOrganizationByID(organizationID int) (*Organization, error) {
itgurl := itg.BuildURL(fmt.Sprintf("/organizations/%d", organizationID))
body := itg.GetRequest(itgurl)
organization := &Organization{}
err := json.Unmarshal(body, organization)
check(err)
return organization
if err != nil {
return nil, fmt.Errorf("could not get organization: %s", err)
}
return organization, nil
}
//GetOrganizationByName expects an exact matching organization name and returns an OrganizationList
func (itg *ITGAPI) GetOrganizationByName(organizationName string) *OrganizationList {
func (itg *ITGAPI) GetOrganizationByName(organizationName string) (*OrganizationList, error) {
itgurl := itg.BuildURL("/organizations")
params := url.Values{}
params.Add("filter[name]", organizationName)
@ -56,6 +58,8 @@ func (itg *ITGAPI) GetOrganizationByName(organizationName string) *OrganizationL
body := itg.GetRequest(itgurl)
organization := &OrganizationList{}
err := json.Unmarshal(body, organization)
check(err)
return organization
if err != nil {
return nil, fmt.Errorf("could not get organization: %s", err)
}
return organization, nil
}