Improve logging
This commit is contained in:
parent
16c240f231
commit
c9370cda00
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue