Skip to content

Commit

Permalink
chore: move err handle into client & leverage HTTPToCode
Browse files Browse the repository at this point in the history
  • Loading branch information
marcsanmi committed Aug 27, 2024
1 parent 1c36f1b commit bf7d9b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/querier/vcs/client/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"golang.org/x/oauth2"

vcsv1 "github.com/grafana/pyroscope/api/gen/proto/go/vcs/v1"
"github.com/grafana/pyroscope/pkg/util/connectgrpc"
)

// GithubClient returns a github client.
Expand All @@ -28,6 +29,11 @@ type githubClient struct {
func (gh *githubClient) GetCommit(ctx context.Context, owner, repo, ref string) (*vcsv1.GetCommitResponse, error) {
commit, _, err := gh.client.Repositories.GetCommit(ctx, owner, repo, ref, nil)
if err != nil {
var githubErr *github.ErrorResponse
if errors.As(err, &githubErr) {
code := connectgrpc.HTTPToCode(int32(githubErr.Response.StatusCode))
return nil, connect.NewError(code, err)
}
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/vcs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (q *Service) GetCommit(ctx context.Context, req *connect.Request[vcsv1.GetC

commit, err := q.tryGetCommit(ctx, ghClient, owner, repo, ref)
if err != nil {
return nil, client.MapErrorToConnectCode(err)
return nil, err
}

return connect.NewResponse(commit), nil
Expand Down

0 comments on commit bf7d9b8

Please sign in to comment.