Add error checks per report from errcheck-ng

This commit is contained in:
Oleksii Kliukin
2017-06-08 10:41:44 +02:00
committed by Oleksii Kliukin
parent 292a9bda05
commit bc0e9ab4bc
9 changed files with 48 additions and 19 deletions
+3 -1
View File
@@ -56,7 +56,9 @@ func KubernetesRestClient(c *rest.Config) (*rest.RESTClient, error) {
)
return nil
})
schemeBuilder.AddToScheme(api.Scheme)
if err := schemeBuilder.AddToScheme(api.Scheme); err != nil {
return nil, fmt.Errorf("could not apply functions to register PostgreSQL TPR type: %v", err)
}
return rest.RESTClientFor(c)
}
+7 -2
View File
@@ -58,7 +58,7 @@ func NewTeamsAPI(url string, log *logrus.Logger) *API {
}
// TeamInfo returns information about a given team using its ID and a token to authenticate to the API service.
func (t *API) TeamInfo(teamID, token string) (*team, error) {
func (t *API) TeamInfo(teamID, token string) (tm *team, er error) {
url := fmt.Sprintf("%s/teams/%s", t.url, teamID)
t.logger.Debugf("Request url: %s", url)
req, err := http.NewRequest("GET", url, nil)
@@ -71,7 +71,12 @@ func (t *API) TeamInfo(teamID, token string) (*team, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() {
if err:= resp.Body.Close(); err != nil {
er = fmt.Errorf("error when closing response; %v", err)
tm = nil
}
}()
if resp.StatusCode != 200 {
var raw map[string]json.RawMessage
d := json.NewDecoder(resp.Body)
+3 -1
View File
@@ -148,7 +148,9 @@ func TestInfo(t *testing.T) {
t.Errorf("Authorization token is wrong or not provided")
}
w.WriteHeader(tc.inCode)
fmt.Fprint(w, tc.in)
if _, err := fmt.Fprint(w, tc.in); err != nil {
t.Errorf("Error writing teams api response %v", err)
}
}))
defer ts.Close()
api := NewTeamsAPI(ts.URL, logger)