Version that runs with new file upload stream and cleverswarm
This commit is contained in:
@@ -121,7 +121,7 @@ async def call_cleverthis_post_put_api(
|
||||
# ============= GET Helper function =============
|
||||
async def call_cleverthis_get_api(
|
||||
message: AMQMessage,
|
||||
pattern: str,
|
||||
pattern_or_data: str | dict,
|
||||
api_method: Callable[[Tuple[AnyStr | Any, ...], Any], Coroutine],
|
||||
authenticated_user: Any
|
||||
) -> AMQResponse:
|
||||
@@ -134,14 +134,20 @@ async def call_cleverthis_get_api(
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
match = re.search(pattern, message.path)
|
||||
if match:
|
||||
crt: Coroutine = api_method(match.groups(), authenticated_user)
|
||||
result: str = await crt
|
||||
return AMQResponseFactory.of(message.id, 200, "text/plain", result.encode('utf-8'), message.trace_info)
|
||||
args = None
|
||||
if isinstance(pattern_or_data, dict):
|
||||
args = pattern_or_data
|
||||
else:
|
||||
_msg = f"Unexpected URL: {message.path}, expected pattern: {pattern}"
|
||||
return AMQResponseFactory.of(message.id, 404, "text/plain", _msg.encode('utf-8'), message.trace_info)
|
||||
match = re.search(pattern_or_data, message.path)
|
||||
if match:
|
||||
args = match.groups()
|
||||
else:
|
||||
_msg = f"Unexpected URL: {message.path}, expected pattern: {pattern_or_data}"
|
||||
return AMQResponseFactory.of(message.id, 404, "text/plain", _msg.encode('utf-8'), message.trace_info)
|
||||
crt: Coroutine = api_method(args, authenticated_user)
|
||||
result: str = await crt
|
||||
return AMQResponseFactory.of(message.id, 200, "text/plain", result.encode('utf-8'), message.trace_info)
|
||||
|
||||
except HTTPException as http_error:
|
||||
tb = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||
logging.error(f" [E] Error in {tb.filename}, line {tb.lineno}, function '{tb.name}': {http_error}")
|
||||
|
||||
Reference in New Issue
Block a user