mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
[PR #11561/7436c0c9 backport][stable-12] replace literal HTTP codes with http.HTTPStatus (#11568)
replace literal HTTP codes with `http.HTTPStatus` (#11561)
* replace literal HTTP codes with http.HTTPStatus
* add changelog frag
(cherry picked from commit 7436c0c9ba)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
@@ -97,6 +97,7 @@ except ImportError:
|
||||
|
||||
import json
|
||||
import time
|
||||
from http import HTTPStatus
|
||||
from urllib.error import HTTPError
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
@@ -177,9 +178,9 @@ def post_request(generated_jwt, installation_id, api_base):
|
||||
display.vvv(f"Error returned: {error_body}")
|
||||
except Exception:
|
||||
error_body = {}
|
||||
if e.code == 404:
|
||||
if e.code == HTTPStatus.NOT_FOUND:
|
||||
raise AnsibleError("Github return error. Please confirm your installation_id value is valid") from e
|
||||
elif e.code == 401:
|
||||
elif e.code == HTTPStatus.UNAUTHORIZED:
|
||||
raise AnsibleError("Github return error. Please confirm your private key is valid") from e
|
||||
raise AnsibleError(f"Unexpected data returned: {e} -- {error_body}") from e
|
||||
response_body = response.read()
|
||||
|
||||
Reference in New Issue
Block a user