home: Fix parsing bug for initial narrows.

There's more we'll want to do here, but this at least avoids error
emails when users attempt to misuse this interface.
This commit is contained in:
Tim Abbott 2019-03-08 17:36:01 -08:00
parent 8fbba64377
commit 4f02795830
2 changed files with 4 additions and 3 deletions

View File

@ -404,10 +404,10 @@ class HomeTest(ZulipTestCase):
def test_bad_narrow(self) -> None: def test_bad_narrow(self) -> None:
email = self.example_email("hamlet") email = self.example_email("hamlet")
self.login(email) self.login(email)
with patch('logging.exception') as mock: with patch('logging.warning') as mock:
result = self._get_home_page(stream='Invalid Stream') result = self._get_home_page(stream='Invalid Stream')
mock.assert_called_once() mock.assert_called_once()
self.assertEqual(mock.call_args_list[0][0][0], "Narrow parsing exception") self.assertEqual(mock.call_args_list[0][0][0], "Invalid narrow requested, ignoring")
self._sanity_check(result) self._sanity_check(result)
def test_bad_pointer(self) -> None: def test_bad_pointer(self) -> None:

View File

@ -117,12 +117,13 @@ def home_real(request: HttpRequest) -> HttpResponse:
narrow_topic = request.GET.get("topic") narrow_topic = request.GET.get("topic")
if request.GET.get("stream"): if request.GET.get("stream"):
try: try:
# TODO: We should support stream IDs and PMs here as well.
narrow_stream_name = request.GET.get("stream") narrow_stream_name = request.GET.get("stream")
(narrow_stream, ignored_rec, ignored_sub) = access_stream_by_name( (narrow_stream, ignored_rec, ignored_sub) = access_stream_by_name(
user_profile, narrow_stream_name) user_profile, narrow_stream_name)
narrow = [["stream", narrow_stream.name]] narrow = [["stream", narrow_stream.name]]
except Exception: except Exception:
logging.exception("Narrow parsing exception", extra=dict(request=request)) logging.warning("Invalid narrow requested, ignoring", extra=dict(request=request))
if narrow_stream is not None and narrow_topic is not None: if narrow_stream is not None and narrow_topic is not None:
narrow.append(["topic", narrow_topic]) narrow.append(["topic", narrow_topic])