Repository URL to install this package:
|
Version:
0.8.1 ▾
|
from supertenant import consts
try:
from typing import Any, Dict, Optional
except ImportError:
pass
from supertenant.supermeter.data import HTTPData, HTTPServerData
from supertenant.supermeter.logger import log_integration_module_error
DEFAULT_HTTP_RC = 429
def reject_http_request(action, action_desc, finish_data):
# type: (int, Optional[Dict[str, Any]], HTTPData) -> int
if action != consts.ACTION_REJECT:
log_integration_module_error(
"HTTP_REQUESTS_UTILS",
"reject_http_request called with action != REJECT (action={action})".format(action=action),
)
rc = None
if action_desc is not None and isinstance(action_desc, dict):
# TODO: use consts/ protobuf for http_rc
http_reject = action_desc.get("HttpReject")
if http_reject is not None:
rc = http_reject.get("http_rc")
else:
try:
rc = int(action_desc.get("http_rc")) # type: ignore
except Exception:
rc = DEFAULT_HTTP_RC
if rc is None:
# TODO: Log this
rc = DEFAULT_HTTP_RC
if isinstance(finish_data, HTTPServerData):
finish_data.set_status(rc)
finish_data.mark_error()
return rc