File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 7
7
"io"
8
8
"net/http"
9
9
"net/url"
10
+ "regexp"
10
11
"strings"
11
12
12
13
"github.com/spf13/cobra"
@@ -295,8 +296,19 @@ func isInsufficientScopeError(r *http.Response) error {
295
296
return nil
296
297
}
297
298
298
- missingScopes := strings .Split (body .Message , "Insufficient scope, expected any of: " )[1 ]
299
- recommendedScopeToAdd := strings .Split (missingScopes , "," )[0 ]
299
+ var recommendedScopeToAdd string
300
+
301
+ parts := strings .Split (body .Message , "Insufficient scope, expected any of: " )
302
+ if len (parts ) > 1 {
303
+ missingScopes := parts [1 ]
304
+ recommendedScopeToAdd = strings .Split (missingScopes , "," )[0 ]
305
+ } else {
306
+ re := regexp .MustCompile (`scope: ([\w:,_\s]+)` )
307
+ matches := re .FindStringSubmatch (body .Message )
308
+ if len (matches ) > 1 {
309
+ recommendedScopeToAdd = matches [1 ]
310
+ }
311
+ }
300
312
301
313
return fmt .Errorf (
302
314
"request failed because access token lacks scope: %s.\n " +
You can’t perform that action at this time.
0 commit comments