Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanahuckova committed Jul 4, 2024
1 parent f9c029d commit aac5a8a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions pkg/github/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func New(ctx context.Context, settings models.Settings) (*Client, error) {
// If access token is not set, return downstream error as it is required.
return nil, errorsource.DownstreamError(fmt.Errorf("access token is required"), false)
}

src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: settings.AccessToken},
)
Expand Down Expand Up @@ -267,12 +267,12 @@ func (client *Client) getWorkflowRuns(ctx context.Context, owner, repo, workflow
}

if err != nil {
// If the workflow is not found, return a specific error.
if (response != nil && response.StatusCode == http.StatusNotFound) {
return nil, 0, errorsource.SourceError(backend.ErrorSourceDownstream, errWorkflowNotFound, false)
}
// If the workflow is not found, return a specific error.
if response != nil && response.StatusCode == http.StatusNotFound {
return nil, 0, errorsource.SourceError(backend.ErrorSourceDownstream, errWorkflowNotFound, false)
}
return nil, 0, addErrorSourceToError(fmt.Errorf("fetching workflow runs: %w", err), response)
}
}

workflowRuns = append(workflowRuns, runs.WorkflowRuns...)

Expand Down
12 changes: 7 additions & 5 deletions pkg/github/client/errorsourcehandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
)

var statusErrorStringFromGraphQLPackage = "non-200 OK status code: "

func addErrorSourceToError(err error, resp *googlegithub.Response) error {
// If there is no error or status code is 2xx we are not adding any source and returning nil
if err == nil {
return nil
}

if errors.Is(err, syscall.ECONNREFUSED) {
return errorsource.DownstreamError(err, false);
return errorsource.DownstreamError(err, false)
}
// Unfortunately graphql library that is used is retuning original error from
// client. That error is in "non-200 OK status code: ..." format and has the status in it
// which we can extract and use.
if (strings.Contains(err.Error(),statusErrorStringFromGraphQLPackage)) {
statusCode, statusErr := extractStatusCode(err)
if strings.Contains(err.Error(), statusErrorStringFromGraphQLPackage) {
statusCode, statusErr := extractStatusCode(err)
if statusErr == nil {
return errorsource.SourceError(backend.ErrorSourceFromHTTPStatus(statusCode), err, false)
}
Expand All @@ -37,8 +39,8 @@ func addErrorSourceToError(err error, resp *googlegithub.Response) error {
}
}
// Otherwise we are not adding source which means it is going to be plugin error
// not sure if this is the correct way to handle this as the error might be still coming
// from the package that we are using. We should look into it once we have more data on this.
// not sure if this is the correct way to handle this as the error might be still coming
// from the package that we are using. We should look into it once we have more data on this.
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/github/client/errorsourcehandling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ func TestExtractStatusCode(t *testing.T) {
}
})
}
}
}

0 comments on commit aac5a8a

Please sign in to comment.