Add better error messages to PagureError

This will add better error messages from pagure module, so it's easier to debug
the issue.

Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
Michal Konečný 2023-02-03 14:18:08 +01:00 committed by zlopez
parent 84056e7453
commit 7e5ed8efb4

View file

@ -117,9 +117,24 @@ class Pagure:
"Got status_code '{2}'.".format(issue_id, namespace, response.status_code)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't retrieve issue '{0}' from project '{1}'".format(
issue_id, namespace
(
"Couldn't retrieve issue '{0}' from project '{1}'\n\n"
"Request to '{2}':\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
issue_id,
namespace,
api_url,
response_json,
response.status_code,
)
)
@ -167,7 +182,27 @@ class Pagure:
)
)
raise PagureError("Couldn't close issue '{0}'".format(issue_url))
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
(
"Couldn't close issue '{0}'\n\n"
"Request to '{1}':\n"
"{2}\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
issue_url,
api_url,
status_payload,
response_json,
response.status_code,
)
)
def add_comment_to_issue(self, issue_id: int, namespace: str, comment: str) -> None:
"""
@ -204,7 +239,27 @@ class Pagure:
)
)
raise PagureError("Couldn't comment on issue '{0}'".format(issue_url))
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
(
"Couldn't comment on issue '{0}'\n\n"
"Request to '{1}':\n"
"{2}\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
issue_url,
api_url,
comment_payload,
response_json,
response.status_code,
)
)
def user_exists(self, username: str) -> bool:
"""
@ -232,7 +287,25 @@ class Pagure:
)
)
raise PagureError("Couldn't get user '{0}'".format(username))
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
(
"Couldn't get user '{0}'\n\n"
"Request to '{1}':\n"
"Response:\n"
"{2}\n\n"
"Status code: {3}"
).format(
username,
user_url,
response_json,
response.status_code,
)
)
def new_project(
self,
@ -285,8 +358,28 @@ class Pagure:
namespace, repo, response.status_code
)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't create project '{0}/{1}'".format(namespace, repo)
(
"Couldn't create project '{0}/{1}'\n\n"
"Request to '{2}':\n"
"{3}\n\n"
"Response:\n"
"{4}\n\n"
"Status code: {5}"
).format(
namespace,
repo,
pagure_new_project_url,
payload,
response_json,
response.status_code,
)
)
# Don't create alias without initial commit
@ -315,9 +408,27 @@ class Pagure:
namespace, repo, response.status_code
)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't create alias for project '{0}/{1}'".format(
namespace, repo
(
"Couldn't create alias for project '{0}/{1}'\n\n"
"Request to '{2}':\n"
"{3}\n\n"
"Response:\n"
"{4}\n\n"
"Status code: {5}"
).format(
namespace,
repo,
pagure_new_git_alias_url,
payload,
response_json,
response.status_code,
)
)
@ -437,8 +548,28 @@ class Pagure:
namespace, repo, response.status_code
)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't set monitoring on project '{0}/{1}'".format(namespace, repo)
(
"Couldn't set monitoring on project '{0}/{1}'\n\n"
"Request to '{2}':\n"
"{3}\n\n"
"Response:\n"
"{4}\n\n"
"Status code: {5}"
).format(
namespace,
repo,
monitoring_api_url,
payload,
response_json,
response.status_code,
)
)
def change_project_main_admin(
@ -474,8 +605,28 @@ class Pagure:
namespace, repo, response.status_code
)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't set new admin on project '{0}/{1}'".format(namespace, repo)
(
"Couldn't set new admin on project '{0}/{1}'\n\n"
"Request to '{2}':\n"
"{3}\n\n"
"Response:\n"
"{4}\n\n"
"Status code: {5}"
).format(
namespace,
repo,
admin_api_url,
payload,
response_json,
response.status_code,
)
)
def get_project_contributors(self, namespace: str, repo: str) -> Any:
@ -509,9 +660,25 @@ class Pagure:
"Error when retrieving contributors project '{0}/{1}'. "
"Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't get contributors for project '{0}/{1}'".format(
namespace, repo
(
"Couldn't get contributors for project '{0}/{1}'\n\n"
"Request to '{2}':\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
namespace,
repo,
contributors_api_url,
response_json,
response.status_code,
)
)
@ -546,9 +713,25 @@ class Pagure:
"Error when getting list of branches for project '{0}/{1}'. "
"Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't get list of branches for project '{0}/{1}'".format(
namespace, repo
(
"Couldn't get list of branches for project '{0}/{1}'\n\n"
"Request to '{2}':\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
namespace,
repo,
branches_api_url,
response_json,
response.status_code,
)
)
@ -585,9 +768,25 @@ class Pagure:
"Error when getting default branch for project '{0}/{1}'. "
"Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
"Couldn't get default branch for project '{0}/{1}'".format(
namespace, repo
(
"Couldn't get default branch for project '{0}/{1}'\n\n"
"Request to '{2}':\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
namespace,
repo,
branches_api_url,
response_json,
response.status_code,
)
)
@ -626,6 +825,26 @@ class Pagure:
"Error when retrieving project '{0}/{1}'. "
"Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
raise PagureError("Couldn't get project '{0}/{1}'".format(namespace, repo))
response_json = None
if response.headers.get("content-type") == "application/json":
response_json = response.json()
log.error("Received response: {0}".format(response.json()))
raise PagureError(
(
"Couldn't get project '{0}/{1}'\n\n"
"Request to '{2}':\n\n"
"Response:\n"
"{3}\n\n"
"Status code: {4}"
).format(
namespace,
repo,
contributors_api_url,
response_json,
response.status_code,
)
)
return result