bndr / gojenkins

Jenkins API Client in Go. Looking for maintainers to move this project forward.
Apache License 2.0
863 stars 443 forks source link

Jenkins.Init() should return the status code #289

Open NeonWizard opened 2 years ago

NeonWizard commented 2 years ago

I'm having difficulty connecting to an enterprise Jenkins instance, and can't troubleshoot whether my credentials are invalid or unauthorized, since Jenkins.Init() doesn't tell me the status code, just that it failed.

Suggested change:

j.Version = rsp.Header.Get("X-Jenkins")
if j.Raw == nil || rsp.StatusCode != http.StatusOK {
    return nil, errors.New(fmt.Sprintf("Connection Failed, please verify that the host and credentials are correct. Status Code %d", rsp.StatusCode))
}

Previously suggested by @vperson in https://github.com/bndr/gojenkins/issues/210#issuecomment-808831117