1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-29 23:18:55 +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:
patchback[bot] 2026-03-10 22:14:27 +01:00 committed by GitHub
parent b3782a76e0
commit 25c475a7ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 135 additions and 78 deletions

View file

@ -7,6 +7,7 @@ from __future__ import annotations
import json
import traceback
import typing as t
from http import HTTPStatus
from ansible.module_utils.urls import fetch_url, url_argument_spec
@ -74,13 +75,15 @@ def api_request(
},
)
if info["status"] == 403:
_status = HTTPStatus(info["status"])
if _status == HTTPStatus.FORBIDDEN:
module.fail_json(msg="Token authorization failed", execution_info=json.loads(info["body"]))
elif info["status"] == 404:
elif _status == HTTPStatus.NOT_FOUND:
return None, info
elif info["status"] == 409:
elif _status == HTTPStatus.CONFLICT:
module.fail_json(msg="Job executions limit reached", execution_info=json.loads(info["body"]))
elif info["status"] >= 500:
elif _status.is_server_error:
module.fail_json(msg="Rundeck API error", execution_info=json.loads(info["body"]))
try: