diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index 3fa35ea..9806613 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -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