From d35e22f0beafe43b5aec9accdf239e4c6ded82cf Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 25 Nov 2020 09:07:20 +0800 Subject: [PATCH] Provide a hunman readable error message instead of the raw Signed-off-by: rick --- pkg/simple/client/devops/jenkins/pipeline.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/simple/client/devops/jenkins/pipeline.go b/pkg/simple/client/devops/jenkins/pipeline.go index fd8f9dbd..483d8acf 100644 --- a/pkg/simple/client/devops/jenkins/pipeline.go +++ b/pkg/simple/client/devops/jenkins/pipeline.go @@ -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) - if err != nil { - klog.Error(err) + res, _, err := p.Jenkins.SendPureRequestWithHeaderResp(p.Path, p.HttpParameters) + if err != nil { + 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() -- GitLab