Ignore scope suggestions for http 422 (#4809)

HTTP 422 messages are for validation errors, but OAUTH permissions
suggestions get printed anyways. Most times, the user probably has the
right permissions. This fix adds the check to avoid printing a confusing
message.

Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
Des Preston 2021-12-01 13:13:48 -05:00 committed by GitHub
parent 6906dea671
commit 8f9548fd37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -206,7 +206,7 @@ func (err HTTPError) ScopesSuggestion() string {
// ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth
// scopes in case a server response indicates that there are missing scopes.
func ScopesSuggestion(resp *http.Response) string {
if resp.StatusCode < 400 || resp.StatusCode > 499 {
if resp.StatusCode < 400 || resp.StatusCode > 499 || resp.StatusCode == 422 {
return ""
}

View file

@ -208,6 +208,11 @@ func TestHTTPError_ScopesSuggestion(t *testing.T) {
resp: makeResponse(404, "https://api.github.com/gists", "", "gist, delete_repo"),
want: ``,
},
{
name: "http code is 422",
resp: makeResponse(422, "https://api.github.com/gists", "", "gist"),
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {