OpenRailAssociation / github-org-manager

Manage a GitHub organization, its members, teams, repository permissions and more
Apache License 2.0
6 stars 2 forks source link

Catch `BadCredentialsException` #18

Open mxmehl opened 7 months ago

mxmehl commented 7 months ago

This error occurs if the GitHub token is invalid:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.[12](https://github.com/OpenRailAssociation/openrail-org-config/pull/3/checks#step:6:13).3/x64/bin/gh-org-mgr", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/gh_org_mgr/manage.py", line 51, in main
    org.login(cfg_org.get("org_name", ""), cfg_app.get("github_token", ""))
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/gh_org_mgr/_gh_org.py", line 46, in login
    self.org = self.gh.get_organization(orgname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/github/MainClass.py", line 396, in get_organization
    headers, data = self.__requester.requestJsonAndCheck("GET", f"/orgs/{login}")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/github/Requester.py", line 548, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/github/Requester.py", line 609, in __check
    raise self.createException(status, responseHeaders, data)
github.GithubException.BadCredentialsException: 401 {"message": "Bad credentials", "documentation_url": "https://docs.github.com/rest"}
Error: Process completed with exit code 1.