1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 05:09:12 +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:
Alexei Znamensky 2026-03-11 10:03:55 +13:00 committed by GitHub
parent 1554f23bfb
commit 7436c0c9ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 135 additions and 78 deletions

View file

@ -8,6 +8,7 @@ import re
import time
import traceback
import typing as t
from http import HTTPStatus
THIRD_LIBRARIES_IMP_ERR = None
try:
@ -70,7 +71,7 @@ def session_method_wrapper(f):
raise HwcClientException(0, f"Parsing response to json failed, error: {ex}") from ex
code = r.status_code
if code not in [200, 201, 202, 203, 204, 205, 206, 207, 208, 226]:
if not HTTPStatus(code).is_success:
msg = ""
for i in ["message", "error.message"]:
try:
@ -81,7 +82,7 @@ def session_method_wrapper(f):
else:
msg = str(result)
if code == 404:
if code == HTTPStatus.NOT_FOUND:
raise HwcClientException404(msg)
raise HwcClientException(code, msg)