ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware).
(ctx context.Context)
| 74 | |
| 75 | // ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware). |
| 76 | func ContextWithGitHubErrors(ctx context.Context) context.Context { |
| 77 | if ctx == nil { |
| 78 | ctx = context.Background() |
| 79 | } |
| 80 | if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok { |
| 81 | // If the context already has GitHubCtxErrors, we just empty the slices to start fresh |
| 82 | val.api = []*GitHubAPIError{} |
| 83 | val.graphQL = []*GitHubGraphQLError{} |
| 84 | val.raw = []*GitHubRawAPIError{} |
| 85 | } else { |
| 86 | // If not, we create a new GitHubCtxErrors and set it in the context |
| 87 | ctx = context.WithValue(ctx, GitHubErrorKey{}, &GitHubCtxErrors{}) |
| 88 | } |
| 89 | |
| 90 | return ctx |
| 91 | } |
| 92 | |
| 93 | // GetGitHubAPIErrors retrieves the slice of GitHubAPIErrors from the context. |
| 94 | func GetGitHubAPIErrors(ctx context.Context) ([]*GitHubAPIError, error) { |
no outgoing calls