Skip to content

Commit 22a3c4d

Browse files
committed
github: Add ErrNoVerifiedGitHubPrimaryEmail error
Add a `ErrNoVerifiedGitHubPrimaryEmail` error to FetchUser() function so that callers have the chance to handle the error explicitly. For example, instead of forwarding the error message, we can more easily direct users to a HTML page explaining the problem.
1 parent 8333bec commit 22a3c4d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

providers/github/github.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ var (
3333
EmailURL = "https://api.github.com/user/emails"
3434
)
3535

36+
var (
37+
// ErrNoVerifiedGitHubPrimaryEmail user doesn't have verified primary email on GitHub
38+
ErrNoVerifiedGitHubPrimaryEmail = errors.New("The user does not have a verified, primary email address on GitHub")
39+
)
40+
3641
// New creates a new Github provider, and sets up important connection details.
3742
// You should always call `github.New` to get a new Provider. Never try to create
3843
// one manually.
@@ -207,7 +212,7 @@ func getPrivateMail(p *Provider, sess *Session) (email string, err error) {
207212
return v.Email, nil
208213
}
209214
}
210-
return email, fmt.Errorf("The user does not have a verified, primary email address on GitHub")
215+
return email, ErrNoVerifiedGitHubPrimaryEmail
211216
}
212217

213218
func newConfig(provider *Provider, authURL, tokenURL string, scopes []string) *oauth2.Config {

0 commit comments

Comments
 (0)