Update error handling
This commit is contained in:
parent
09e6dea75a
commit
3440d00924
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
example/main.go
|
@ -38,17 +38,19 @@ type OrganizationList struct {
|
|||||||
|
|
||||||
//GetOrganizationByID expects an ITG organization ID
|
//GetOrganizationByID expects an ITG organization ID
|
||||||
//Returns a pointer to an Organization struct
|
//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))
|
itgurl := itg.BuildURL(fmt.Sprintf("/organizations/%d", organizationID))
|
||||||
body := itg.GetRequest(itgurl)
|
body := itg.GetRequest(itgurl)
|
||||||
organization := &Organization{}
|
organization := &Organization{}
|
||||||
err := json.Unmarshal(body, organization)
|
err := json.Unmarshal(body, organization)
|
||||||
check(err)
|
if err != nil {
|
||||||
return organization
|
return nil, fmt.Errorf("could not get organization: %s", err)
|
||||||
|
}
|
||||||
|
return organization, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetOrganizationByName expects an exact matching organization name and returns an OrganizationList
|
//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")
|
itgurl := itg.BuildURL("/organizations")
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("filter[name]", organizationName)
|
params.Add("filter[name]", organizationName)
|
||||||
@ -56,6 +58,8 @@ func (itg *ITGAPI) GetOrganizationByName(organizationName string) *OrganizationL
|
|||||||
body := itg.GetRequest(itgurl)
|
body := itg.GetRequest(itgurl)
|
||||||
organization := &OrganizationList{}
|
organization := &OrganizationList{}
|
||||||
err := json.Unmarshal(body, organization)
|
err := json.Unmarshal(body, organization)
|
||||||
check(err)
|
if err != nil {
|
||||||
return organization
|
return nil, fmt.Errorf("could not get organization: %s", err)
|
||||||
|
}
|
||||||
|
return organization, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user