This is an automated email from the ASF dual-hosted git repository. klesh pushed a commit to branch kw-jira-testconn-400 in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 33569d5e511b31d2a7483729ce2de847ce2a4eef Author: Klesh Wong <[email protected]> AuthorDate: Sun Feb 25 15:18:01 2024 +0800 fix: invalid url detection not working correctly --- backend/plugins/jira/api/connection_api.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/plugins/jira/api/connection_api.go b/backend/plugins/jira/api/connection_api.go index aee973ef8..2a0fe3e32 100644 --- a/backend/plugins/jira/api/connection_api.go +++ b/backend/plugins/jira/api/connection_api.go @@ -54,22 +54,22 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC // serverInfo checking res, err := apiClient.Get("api/2/serverInfo", nil, nil) if err != nil { + // check if `/rest/` was missing + if strings.Contains(err.Error(), "status code 404") && !strings.HasSuffix(connection.Endpoint, "/rest/") { + endpointUrl, err := url.Parse(connection.Endpoint) + if err != nil { + return nil, errors.Convert(err) + } + refUrl, err := url.Parse("/rest/") + if err != nil { + return nil, errors.Convert(err) + } + restUrl := endpointUrl.ResolveReference(refUrl) + return nil, errors.NotFound.New(fmt.Sprintf("Seems like an invalid Endpoint URL, please try %s", restUrl.String())) + } return nil, err } serverInfoFail := "Failed testing the serverInfo: [ " + res.Request.URL.String() + " ]" - // check if `/rest/` was missing - if res.StatusCode == http.StatusNotFound && !strings.HasSuffix(connection.Endpoint, "/rest/") { - endpointUrl, err := url.Parse(connection.Endpoint) - if err != nil { - return nil, errors.Convert(err) - } - refUrl, err := url.Parse("/rest/") - if err != nil { - return nil, errors.Convert(err) - } - 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("Error username/password") }
