diff --git a/backend/plugins/sonarqube/api/connection_api.go b/backend/plugins/sonarqube/api/connection_api.go index 29f26370cf4..9058ce3f7e8 100644 --- a/backend/plugins/sonarqube/api/connection_api.go +++ b/backend/plugins/sonarqube/api/connection_api.go @@ -19,6 +19,7 @@ package api import ( "context" + "fmt" "net/http" "github.com/apache/incubator-devlake/core/errors" @@ -95,6 +96,10 @@ func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, if testConnectionErr != nil { return nil, plugin.WrapTestConnectionErrResp(basicRes, testConnectionErr) } + if testConnectionResult.Status != http.StatusOK { + errMsg := fmt.Sprintf("Test connection fail, unexpected status code: %d", testConnectionResult.Status) + return nil, plugin.WrapTestConnectionErrResp(basicRes, errors.Default.New(errMsg)) + } return &plugin.ApiResourceOutput{Body: testConnectionResult, Status: http.StatusOK}, nil } @@ -116,6 +121,10 @@ func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResource if testConnectionErr != nil { return nil, plugin.WrapTestConnectionErrResp(basicRes, testConnectionErr) } + if testConnectionResult.Status != http.StatusOK { + errMsg := fmt.Sprintf("Test connection fail, unexpected status code: %d", testConnectionResult.Status) + return nil, plugin.WrapTestConnectionErrResp(basicRes, errors.Default.New(errMsg)) + } return &plugin.ApiResourceOutput{Body: testConnectionResult, Status: http.StatusOK}, nil }