Skip to content

Commit 32d0045

Browse files
authored
docs: Update code snippets to use errors package for type assertions (#3746)
1 parent 46f1bf2 commit 32d0045

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ To detect this condition of error, you can check if its type is
267267

268268
```go
269269
stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
270-
if _, ok := err.(*github.AcceptedError); ok {
270+
if errors.As(err, new(*github.AcceptedError)) {
271271
log.Println("scheduled on GitHub side")
272272
}
273273
```

github/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ To detect an API rate limit error, you can check if its type is *[RateLimitError
111111
For secondary rate limits, you can check if its type is *[AbuseRateLimitError]:
112112
113113
repos, _, err := client.Repositories.List(ctx, "", nil)
114-
if _, ok := err.(*github.RateLimitError); ok {
114+
if errors.As(err, new(*github.RateLimitError)) {
115115
log.Println("hit rate limit")
116116
}
117-
if _, ok := err.(*github.AbuseRateLimitError); ok {
117+
if errors.As(err, new(*github.AbuseRateLimitError)) {
118118
log.Println("hit secondary rate limit")
119119
}
120120
@@ -132,7 +132,7 @@ To detect this condition of error, you can check if its type is
132132
*[AcceptedError]:
133133
134134
stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
135-
if _, ok := err.(*github.AcceptedError); ok {
135+
if errors.As(err, new(*github.AcceptedError)) {
136136
log.Println("scheduled on GitHub side")
137137
}
138138

0 commit comments

Comments
 (0)