Skip to content

issue#50: DPNLPF-2184: fix http_request #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions smart_kit/action/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
9 changes: 9 additions & 0 deletions smart_kit/template/static/references/actions/actions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"exception_action": {
"type": "string",
"command": "ANSWER_TO_USER",
"nodes": {
"answer": [
Expand All @@ -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"
}
}