From 3440d009249062212a4ba84eef32467927436891 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Sun, 22 Jul 2018 01:22:22 -0600 Subject: [PATCH] Update error handling --- .gitignore | 1 + itglue/organizations.go | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9be5652 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +example/main.go \ No newline at end of file diff --git a/itglue/organizations.go b/itglue/organizations.go index a307c64..df32a0f 100644 --- a/itglue/organizations.go +++ b/itglue/organizations.go @@ -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 }