Improve logging

This commit is contained in:
Tomasz Sęk 2019-01-14 18:18:52 +01:00
parent 16c240f231
commit c9370cda00
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
2 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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)
}