Provide a hunman readable error message instead of the raw

Signed-off-by: rick <rick@jenkins-zh.cn>
This commit is contained in:
rick
2020-11-25 09:07:20 +08:00
parent 75e0cf27e4
commit d35e22f0be

View File

@@ -18,6 +18,7 @@ package jenkins
import (
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
@@ -98,9 +99,20 @@ func (p *Pipeline) GetPipeline() (*devops.Pipeline, error) {
}
func (p *Pipeline) ListPipelines() (*devops.PipelineList, error) {
res, err := p.Jenkins.SendPureRequest(p.Path, p.HttpParameters)
res, _, err := p.Jenkins.SendPureRequestWithHeaderResp(p.Path, p.HttpParameters)
if err != nil {
klog.Error(err)
if jErr, ok := err.(*JkError); ok {
switch jErr.Code {
case 404:
err = fmt.Errorf("please check if there're any Jenkins plugins issues exist")
default:
err = fmt.Errorf("please check if Jenkins is running well")
}
klog.Errorf("API '%s' request response code is '%d'", p.Path, jErr.Code)
} else {
err = fmt.Errorf("unknow errors happend when coumunicate with Jenkins")
klog.Error(err)
}
return nil, err
}
count, err := p.searchPipelineCount()