🌐 AI搜索 & 代理 主页
Skip to content

Commit dd7f537

Browse files
committed
add raw errors to context
1 parent 234565b commit dd7f537

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/errors/error.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func ContextWithGitHubErrors(ctx context.Context) context.Context {
7575
// If the context already has GitHubCtxErrors, we just empty the slices to start fresh
7676
val.api = []*GitHubAPIError{}
7777
val.graphQL = []*GitHubGraphQLError{}
78+
val.raw = []*GitHubRawAPIError{}
7879
} else {
7980
// If not, we create a new GitHubCtxErrors and set it in the context
8081
ctx = context.WithValue(ctx, GitHubErrorKey{}, &GitHubCtxErrors{})
@@ -99,6 +100,14 @@ func GetGitHubGraphQLErrors(ctx context.Context) ([]*GitHubGraphQLError, error)
99100
return nil, fmt.Errorf("context does not contain GitHubCtxErrors")
100101
}
101102

103+
// GetGitHubRawAPIErrors retrieves the slice of GitHubRawAPIErrors from the context.
104+
func GetGitHubRawAPIErrors(ctx context.Context) ([]*GitHubRawAPIError, error) {
105+
if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
106+
return val.raw, nil // return the slice of raw API errors from the context
107+
}
108+
return nil, fmt.Errorf("context does not contain GitHubCtxErrors")
109+
}
110+
102111
func NewGitHubAPIErrorToCtx(ctx context.Context, message string, resp *github.Response, err error) (context.Context, error) {
103112
apiErr := newGitHubAPIError(message, resp, err)
104113
if ctx != nil {

0 commit comments

Comments
 (0)