mirror of
https://git.centos.org/centos/centpkg.git
synced 2025-02-23 08:12:55 +00:00
get_canonical_repo_name: Better handle HTTP errors
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
This commit is contained in:
parent
a35f1acdfd
commit
8c605fd2ee
1 changed files with 11 additions and 1 deletions
|
@ -18,8 +18,9 @@ import re
|
|||
import requests
|
||||
import sys
|
||||
from datetime import date, datetime
|
||||
from http import HTTPStatus
|
||||
from pyrpkg import rpkgError
|
||||
from requests.exceptions import ConnectionError
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
from configparser import NoOptionError, NoSectionError
|
||||
from urllib.parse import quote_plus, urlparse
|
||||
|
||||
|
@ -229,6 +230,15 @@ def get_canonical_repo_name(config, repo_url):
|
|||
rv_json = rv.json()
|
||||
|
||||
canonical_repo_name = rv_json['forked_from_project']['name']
|
||||
|
||||
except HTTPError as e:
|
||||
# We got a 4xx or 5xx error code from the URL lookup
|
||||
if e.response.status_code == HTTPStatus.FORBIDDEN:
|
||||
raise rpkgError("Insufficient Gitlab API permissions. Missing token?")
|
||||
|
||||
# Other errors are unexpected, so re-raise them
|
||||
raise
|
||||
|
||||
except KeyError as e:
|
||||
# There was no 'forked_from_project' key, likely meaning the
|
||||
# user lacked permissions to read the API. Usually this means
|
||||
|
|
Loading…
Add table
Reference in a new issue