From 8c605fd2ee1cb66f0e5e0455f52c49812e3b2b16 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jul 10 2024 12:51:08 +0000 Subject: get_canonical_repo_name: Better handle HTTP errors Signed-off-by: Stephen Gallagher --- 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