diff --git a/smart_kit/action/http.py b/smart_kit/action/http.py index 7f383630..be792fe9 100644 --- a/smart_kit/action/http.py +++ b/smart_kit/action/http.py @@ -77,7 +77,11 @@ async def _make_response(self, request_parameters: dict, user: BaseUser): async with aiohttp.request(**request_parameters) as response: response.raise_for_status() self._log_response(user, response) - return response + try: + return await response.json() + except aiohttp.client_exceptions.ContentTypeError: + return await response.content.read() + return None except (aiohttp.ServerTimeoutError, asyncio.TimeoutError): self.error = self.TIMEOUT except aiohttp.ClientError: @@ -118,11 +122,7 @@ async def process_result(self, response, user, text_preprocessing_result, params behavior_description = user.descriptions["behaviors"][self.behavior] if self.behavior else None action = None if self.error is None: - try: - data = await response.json() - except aiohttp.client_exceptions.ContentTypeError: - data = None - user.variables.set(self.store, data) + user.variables.set(self.store, response) action = behavior_description.success_action if behavior_description else None elif behavior_description is not None: if self.error == self.TIMEOUT: @@ -139,6 +139,6 @@ async def run(self, user: BaseUser, text_preprocessing_result: BaseTextPreproces request_parameters = self._get_request_params(user, text_preprocessing_result, params) self._log_request(user, request_parameters) response = await self._make_response(request_parameters, user) - if response: - log("response data: %(body)s", params={"body": response.json()}, level="INFO") + if response is not None: + log("response data: %(body)s", params={"body": response}, level="INFO") return await self.process_result(response, user, text_preprocessing_result, params) diff --git a/smart_kit/template/static/references/actions/actions.json b/smart_kit/template/static/references/actions/actions.json index 1dc9b933..89449cdc 100644 --- a/smart_kit/template/static/references/actions/actions.json +++ b/smart_kit/template/static/references/actions/actions.json @@ -1,5 +1,6 @@ { "exception_action": { + "type": "string", "command": "ANSWER_TO_USER", "nodes": { "answer": [ @@ -21,5 +22,13 @@ "type": "template", "template": "{{ payload.get('new_session', False) and settings['template_settings'].get('reset_context_on_new_session', False)}}" } + }, + "exception_reset_scenario": { + "type": "external", + "action": "exception_action" + }, + "timeout_reset_scenario": { + "type": "external", + "action": "exception_action" } } \ No newline at end of file