From 59ad2137675ad4db4e6551f7397849ee305fe65d Mon Sep 17 00:00:00 2001 From: abeizn Date: Thu, 14 Mar 2024 14:12:15 +0800 Subject: [PATCH] fix: jira server test connection bug (#7165) --- backend/plugins/jira/api/connection_api.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/plugins/jira/api/connection_api.go b/backend/plugins/jira/api/connection_api.go index d206ccdfda9..9b6071b15fc 100644 --- a/backend/plugins/jira/api/connection_api.go +++ b/backend/plugins/jira/api/connection_api.go @@ -70,8 +70,11 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC restUrl := endpointUrl.ResolveReference(refUrl) return nil, errors.NotFound.New(fmt.Sprintf("Seems like an invalid Endpoint URL, please try %s", restUrl.String())) } - if res.StatusCode == http.StatusUnauthorized { - return nil, errors.HttpStatus(http.StatusBadRequest).New("Please check your credential") + if res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusForbidden { + return nil, errors.HttpStatus(res.StatusCode).New("Please check your credential") + } + if res.StatusCode != http.StatusOK { + return nil, errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("%s unexpected status code: %d", serverInfoFail, res.StatusCode)) } resBody := &models.JiraServerInfo{} @@ -86,9 +89,6 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC return nil, errors.Default.New(fmt.Sprintf("%s Support JIRA Server 7+ only", serverInfoFail)) } } - if res.StatusCode != http.StatusOK { - return nil, errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("%s unexpected status code: %d", serverInfoFail, res.StatusCode)) - } // verify credential getStatusFail := "an error occurred while making request to `/rest/agile/1.0/board`" @@ -100,7 +100,7 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC errMsg := "" if res.StatusCode == http.StatusUnauthorized { - return nil, errors.HttpStatus(http.StatusBadRequest).New("Please check your credential") + return nil, errors.HttpStatus(res.StatusCode).New("Please check your credential") } if res.StatusCode != http.StatusOK { @@ -111,9 +111,7 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC body.Success = true body.Message = "success" body.Connection = &connection - if err != nil { - return nil, err - } + return &body, nil }