From 8f9548fd37ad9f794fdeb14955d623e72eefcdfe Mon Sep 17 00:00:00 2001 From: Des Preston Date: Wed, 1 Dec 2021 13:13:48 -0500 Subject: [PATCH] Ignore scope suggestions for http 422 (#4809) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ć --- api/client.go | 2 +- api/client_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/client.go b/api/client.go index 3b6ddaf9c..3fcf0d930 100644 --- a/api/client.go +++ b/api/client.go @@ -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 "" } diff --git a/api/client_test.go b/api/client_test.go index 415f52366..ccf911f94 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -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) {