This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch kw-7000-jira-testconn-400
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 6cbee5852701dd8ed0090b619d595cdc77c829b5
Author: Klesh Wong <[email protected]>
AuthorDate: Tue Feb 27 16:48:51 2024 +0800

    fix: jira test connection user/pass incorrect message not working
---
 backend/helpers/pluginhelper/api/api_client.go | 24 +++++++-----------------
 backend/plugins/github/api/remote_api.go       |  4 +++-
 backend/plugins/jira/api/connection_api.go     |  2 +-
 3 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/api_client.go 
b/backend/helpers/pluginhelper/api/api_client.go
index 570dc876f..e69a88680 100644
--- a/backend/helpers/pluginhelper/api/api_client.go
+++ b/backend/helpers/pluginhelper/api/api_client.go
@@ -91,17 +91,6 @@ func NewApiClientFromConnection(
                })
        }
 
-       apiClient.SetAfterFunction(func(res *http.Response) errors.Error {
-               if res.StatusCode >= 400 {
-                       bytes, err := io.ReadAll(res.Body)
-                       if err != nil {
-                               return errors.BadInput.Wrap(err, 
fmt.Sprintf("request failed with status code %d", res.StatusCode))
-                       }
-                       return errors.BadInput.New(fmt.Sprintf("request failed 
with status code %d, body: %s", res.StatusCode, string(bytes)))
-               }
-               return nil
-       })
-
        return apiClient, nil
 }
 
@@ -124,16 +113,13 @@ func NewApiClient(
        apiClient.client.Transport = &http.Transport{}
 
        // set insecureSkipVerify
-       insecureSkipVerify, err := 
utils.StrToBoolOr(br.GetConfig("IN_SECURE_SKIP_VERIFY"), false)
-       if err != nil {
-               return nil, errors.Default.Wrap(err, "failed to parse 
IN_SECURE_SKIP_VERIFY")
-       }
+       insecureSkipVerify := 
br.GetConfigReader().GetBool("IN_SECURE_SKIP_VERIFY")
        if insecureSkipVerify {
                apiClient.client.Transport.(*http.Transport).TLSClientConfig = 
&tls.Config{InsecureSkipVerify: true}
        }
 
        if proxy != "" {
-               err = apiClient.SetProxy(proxy)
+               err := apiClient.SetProxy(proxy)
                if err != nil {
                        return nil, errors.Convert(err)
                }
@@ -394,7 +380,11 @@ func UnmarshalResponse(res *http.Response, v interface{}) 
errors.Error {
        }
        err = errors.Convert(json.Unmarshal(resBody, &v))
        if err != nil {
-               return errors.Default.New(fmt.Sprintf("error decoding response 
from %s: raw response: %s", res.Request.URL.String(), string(resBody)))
+               statusCode := res.StatusCode
+               if statusCode == http.StatusUnauthorized || statusCode == 
http.StatusForbidden {
+                       statusCode = http.StatusBadRequest // to avoid Basic 
Auth Dialog poping up
+               }
+               return errors.HttpStatus(statusCode).Wrap(err, 
fmt.Sprintf("error decoding response from %s: raw response: %s", 
res.Request.URL.String(), string(resBody)))
        }
        return nil
 }
diff --git a/backend/plugins/github/api/remote_api.go 
b/backend/plugins/github/api/remote_api.go
index dce870da3..437b0caa5 100644
--- a/backend/plugins/github/api/remote_api.go
+++ b/backend/plugins/github/api/remote_api.go
@@ -91,7 +91,9 @@ func listGithubUserOrgs(
                return nil, nil, err
        }
        var orgs []org
-       errors.Must(api.UnmarshalResponse(orgsBody, &orgs))
+       if err := api.UnmarshalResponse(orgsBody, &orgs); err != nil {
+               return nil, nil, err
+       }
        for _, o := range orgs {
                children = append(children, 
dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo]{
                        Type:     api.RAS_ENTRY_TYPE_GROUP,
diff --git a/backend/plugins/jira/api/connection_api.go 
b/backend/plugins/jira/api/connection_api.go
index aee973ef8..08692a727 100644
--- a/backend/plugins/jira/api/connection_api.go
+++ b/backend/plugins/jira/api/connection_api.go
@@ -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("it 
might you use the right token(password) but with the wrong username.please 
check your username/password")
+               return nil, 
errors.HttpStatus(http.StatusBadRequest).New("Please check your 
username/password")
        }
 
        if res.StatusCode != http.StatusOK {

Reply via email to