Skip to content

Commit 04a842f

Browse files
fix(gists): Use proper GitHub API error handling for observability
The gists.go file was using NewToolResultErrorFromErr for GitHub API errors, which breaks the error middleware tracking that the remote server uses for observability and incident detection. Changed API errors (client.Gists.List, Get, Create, Edit) to use ghErrors.NewGitHubAPIErrorResponse which properly: - Records errors in the context for middleware access - Preserves the response object for rate limit and status tracking - Maintains consistency with other tools that use this pattern This ensures production observability is maintained for Gist operations.
1 parent d89e0c1 commit 04a842f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/github/gists.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/http"
99

10+
ghErrors "github.com/github/github-mcp-server/pkg/errors"
1011
"github.com/github/github-mcp-server/pkg/registry"
1112
"github.com/github/github-mcp-server/pkg/translations"
1213
"github.com/github/github-mcp-server/pkg/utils"
@@ -80,7 +81,7 @@ func ListGists(t translations.TranslationHelperFunc) registry.ServerTool {
8081

8182
gists, resp, err := client.Gists.List(ctx, username, opts)
8283
if err != nil {
83-
return utils.NewToolResultErrorFromErr("failed to list gists", err), nil, nil
84+
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list gists", resp, err), nil, nil
8485
}
8586
defer func() { _ = resp.Body.Close() }()
8687

@@ -139,7 +140,7 @@ func GetGist(t translations.TranslationHelperFunc) registry.ServerTool {
139140

140141
gist, resp, err := client.Gists.Get(ctx, gistID)
141142
if err != nil {
142-
return utils.NewToolResultErrorFromErr("failed to get gist", err), nil, nil
143+
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get gist", resp, err), nil, nil
143144
}
144145
defer func() { _ = resp.Body.Close() }()
145146

@@ -238,7 +239,7 @@ func CreateGist(t translations.TranslationHelperFunc) registry.ServerTool {
238239

239240
createdGist, resp, err := client.Gists.Create(ctx, gist)
240241
if err != nil {
241-
return utils.NewToolResultErrorFromErr("failed to create gist", err), nil, nil
242+
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to create gist", resp, err), nil, nil
242243
}
243244
defer func() { _ = resp.Body.Close() }()
244245

@@ -340,7 +341,7 @@ func UpdateGist(t translations.TranslationHelperFunc) registry.ServerTool {
340341

341342
updatedGist, resp, err := client.Gists.Edit(ctx, gistID, gist)
342343
if err != nil {
343-
return utils.NewToolResultErrorFromErr("failed to update gist", err), nil, nil
344+
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to update gist", resp, err), nil, nil
344345
}
345346
defer func() { _ = resp.Body.Close() }()
346347

0 commit comments

Comments
 (0)