Skip to content

Commit 9d18dff

Browse files
committed
🚧 Added error handling for the authentication token retrieval on github
1 parent d05bf0e commit 9d18dff

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

git_repo/services/ext/github.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,17 @@ def get_auth_token(cls, login, password, prompt=None):
198198
import platform
199199
gh = github3.GitHub()
200200
gh.login(login, password, two_factor_callback=lambda: prompt('2FA code> '))
201-
auth = gh.authorize(login, password,
202-
scopes=[ 'repo', 'delete_repo', 'gist' ],
203-
note='git-repo2 token used on {}'.format(platform.node()),
204-
note_url='https://github.com/guyzmo/git-repo')
205-
return auth.token
201+
try:
202+
auth = gh.authorize(login, password,
203+
scopes=[ 'repo', 'delete_repo', 'gist' ],
204+
note='git-repo2 token used on {}'.format(platform.node()),
205+
note_url='https://github.com/guyzmo/git-repo')
206+
return auth.token
207+
except github3.models.GitHubError as err:
208+
if len(err.args) > 0 and 422 == err.args[0].status_code:
209+
raise ResourceExistsError("A token already exist for this machine on your github account.")
210+
else:
211+
raise err
206212

207213
@property
208214
def user(self):

0 commit comments

Comments
 (0)