From c9370cda00eabf8e9ab29c4afb4b3e2c19093ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C4=99k?= Date: Mon, 14 Jan 2019 18:18:52 +0100 Subject: [PATCH] Improve logging --- pkg/controller/jenkins/client/jenkins.go | 8 ++++---- pkg/controller/jenkins/client/token.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/controller/jenkins/client/jenkins.go b/pkg/controller/jenkins/client/jenkins.go index af2e54c0..b10fcfb8 100644 --- a/pkg/controller/jenkins/client/jenkins.go +++ b/pkg/controller/jenkins/client/jenkins.go @@ -2,13 +2,13 @@ package client import ( "bytes" - "errors" "fmt" "net/http" "os/exec" "strings" "github.com/bndr/gojenkins" + "github.com/pkg/errors" ) var errorNotFound = errors.New("404") @@ -128,15 +128,15 @@ func New(url, user, passwordOrToken string) (Jenkins, error) { BasicAuth: &gojenkins.BasicAuth{Username: user, Password: passwordOrToken}, } if _, err := jenkinsClient.Init(); err != nil { - return nil, err + return nil, errors.Wrap(err, "couldn't init Jenkins API client") } status, err := jenkinsClient.Poll() if err != nil { - return nil, err + return nil, errors.Wrap(err, "couldn't poll data from Jenkins API") } if status != http.StatusOK { - return nil, fmt.Errorf("invalid status code returned: %d", status) + return nil, errors.Errorf("couldn't poll data from Jenkins API, invalid status code returned: %d", status) } return jenkinsClient, nil diff --git a/pkg/controller/jenkins/client/token.go b/pkg/controller/jenkins/client/token.go index c095e3bb..77018eb8 100644 --- a/pkg/controller/jenkins/client/token.go +++ b/pkg/controller/jenkins/client/token.go @@ -1,10 +1,10 @@ package client import ( - "errors" "fmt" "net/http" - "strconv" + + "github.com/pkg/errors" ) type userTokenResponseData struct { @@ -37,7 +37,7 @@ func (jenkins *jenkins) GenerateToken(userName, tokenName string) (*UserToken, e r, err := jenkins.Requester.Post(endpoint, nil, token.raw, data) if err != nil { - return nil, err + return nil, errors.Wrap(err, "couldn't generate API token") } if r.StatusCode == http.StatusOK { @@ -48,5 +48,5 @@ func (jenkins *jenkins) GenerateToken(userName, tokenName string) (*UserToken, e return nil, errors.New(token.raw.Status) } - return nil, errors.New(strconv.Itoa(r.StatusCode)) + return nil, errors.Errorf("couldn't generate API token: %d", r.StatusCode) }