Skip to content

Commit 3781459

Browse files
committed
consolidate logging and fix error results
1 parent 5e08037 commit 3781459

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

rasa_vier_cvg/cvg.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class CVGOutput(OutputChannel):
6767
on_message: Callable[[UserMessage], Awaitable[Any]]
6868
base_url: str
6969
proxy: Optional[str]
70+
task_container: TaskContainer
7071

7172
@classmethod
7273
def name(cls) -> Text:
@@ -92,25 +93,25 @@ def _is_ignored(self, custom_json) -> bool:
9293

9394
async def _perform_request_sync(self, path: str, method: str, data: Optional[any], dialog_id: Optional[str], retries: int = 0) -> (Optional[int], any):
9495
url = f"{self.base_url}{path}"
96+
status = -1
97+
body = None
9598
try:
9699
async with aiohttp.request(method, url, json=data, proxy=self.proxy) as res:
97100
status = res.status
98101
if status == 204:
99102
return status, {}
100103

101104
body = await res.json()
102-
if status < 200 or status >= 300:
103-
logger.error(f"{dialog_id} - Failed to send text message to CVG via {url}: status={status}, body={body}")
104-
105105
return status, body
106106
except aiohttp.ClientResponseError as e:
107-
logger.error(f"{dialog_id} - Failed to send text message to CVG via {url}: status={e.status}, message={e.message}")
107+
return e.status, e.message
108108
except aiohttp.ClientConnectionError:
109109
if retries < 3:
110110
logger.error(f"{dialog_id} - The connection failed, retrying...")
111-
await self._perform_request_sync(path, method, data, dialog_id, retries + 1)
111+
return await self._perform_request_sync(path, method, data, dialog_id, retries + 1)
112112
else:
113113
logger.error(f"{dialog_id} - {retries} retries all failed, that's it!")
114+
return status, body
114115

115116
def _perform_request_async(self, path: str, method: str, data: Optional[any], dialog_id: Optional[str], process_result: Callable[[int, any], Coroutine[Any, Any, None]]):
116117
async def perform():
@@ -122,7 +123,8 @@ async def perform():
122123
async def _perform_request(self, path: str, method: str, data: Optional[any], dialog_id: Optional[str]):
123124
async def handle_result(status_code, response_body):
124125
if not 200 <= status_code < 300:
125-
logger.info(f"{dialog_id} - {method} request to {path} failed: {status_code} with body {response_body}")
126+
url = f"{self.base_url}{path}"
127+
logger.error(f"{dialog_id} - Failed to send command to CVG via {method} {url}: status={status_code}, message={response_body}")
126128
return
127129

128130
if self.blocking_output:

0 commit comments

Comments
 (0)