Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions backend/plugins/jira/api/connection_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix didn't solve the problem, the problem is apiClient.Get overwritten response status code > 400 to 400, so all the error handling code in testConnection of different plugins won't work as they used to be.
This "Error username/password" check will not work, as the res.StatusCode will always be 400 when upstream returned 401 error.

return nil, errors.HttpStatus(http.StatusBadRequest).New("Error username/password")
}
Expand Down