Skip to content

Commit 8f9548f

Browse files
desprestonmislav
andauthored
Ignore scope suggestions for http 422 (cli#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>
1 parent 6906dea commit 8f9548f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

api/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (err HTTPError) ScopesSuggestion() string {
206206
// ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth
207207
// scopes in case a server response indicates that there are missing scopes.
208208
func ScopesSuggestion(resp *http.Response) string {
209-
if resp.StatusCode < 400 || resp.StatusCode > 499 {
209+
if resp.StatusCode < 400 || resp.StatusCode > 499 || resp.StatusCode == 422 {
210210
return ""
211211
}
212212

api/client_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ func TestHTTPError_ScopesSuggestion(t *testing.T) {
208208
resp: makeResponse(404, "https://api.github.com/gists", "", "gist, delete_repo"),
209209
want: ``,
210210
},
211+
{
212+
name: "http code is 422",
213+
resp: makeResponse(422, "https://api.github.com/gists", "", "gist"),
214+
want: "",
215+
},
211216
}
212217
for _, tt := range tests {
213218
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)