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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user