Skip to content
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

Handle timeout exception when fetching raw message. #1486

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,20 @@ def test_fail_get_messages(
None,
True,
),
(
{
"result": "success",
"raw_content": "An exception occurred:"
+ "\n"
+ "The application should continue functioning, but you "
+ "may notice inconsistent behavior in this session.",
},
"An exception occurred:"
+ "\n"
+ "The application should continue functioning, but you "
+ "may notice inconsistent behavior in this session.",
False,
),
],
)
def test_fetch_raw_message_content(
Expand All @@ -1527,11 +1541,14 @@ def test_fetch_raw_message_content(
display_error_called,
message_id=1,
):
self.client.get_raw_message.return_value = response
self.client.call_endpoint.return_value = response

return_value = model.fetch_raw_message_content(message_id)

self.client.get_raw_message.assert_called_once_with(message_id)
self.client.call_endpoint.assert_called_once_with(
f"/messages/{message_id}", method="GET", timeout=5
)
# self.client.get_raw_message.assert_called_once_with(message_id)
assert self.display_error_if_present.called == display_error_called
assert return_value == expected_raw_content

Expand Down
11 changes: 10 additions & 1 deletion zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from urllib.parse import urlparse

import requests
import zulip
from bs4 import BeautifulSoup
from typing_extensions import TypedDict
Expand Down Expand Up @@ -858,7 +859,15 @@ def fetch_raw_message_content(self, message_id: int) -> Optional[str]:
"""
Fetches raw message content of a message using its ID.
"""
response = self.client.get_raw_message(message_id)
# response = self.client.get_raw_message(message_id)
response = dict()
try:
response = self.client.call_endpoint(
f"/messages/{message_id}", method="GET", timeout=5
)
except requests.exceptions.ReadTimeout:
raise

if response["result"] == "success":
return response["raw_content"]
display_error_if_present(response, self.controller)
Expand Down
21 changes: 15 additions & 6 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,12 +1951,21 @@ def __init__(
msg_box = MessageBox(message, controller.model, None)

# Get raw message content widget list
response = controller.model.fetch_raw_message_content(message["id"])

if response is None:
return

body_list = [urwid.Text(response)]
response = ("",)
try:
response = controller.model.fetch_raw_message_content(message["id"])
body_list = [urwid.Text(response)]
except Exception:
response = (
"An exception occurred:"
+ "\n"
+ "The application should continue functioning, but you "
+ "may notice inconsistent behavior in this session.",
)
body_list = [urwid.Text(("area:error", response[0]))]
# response = ("area:error","Connection timed out. \nPlease try again later")
msg_box.header = []
msg_box.footer = []

super().__init__(
controller,
Expand Down
Loading