mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-21 20:59:10 +00:00
replace literal HTTP codes with http.HTTPStatus (#11561)
* replace literal HTTP codes with http.HTTPStatus * add changelog frag
This commit is contained in:
parent
1554f23bfb
commit
7436c0c9ba
18 changed files with 135 additions and 78 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue