Skip to content

Commit

Permalink
Remove path from 404 response (#3165)
Browse files Browse the repository at this point in the history
* Remove path from 404 response

* Remove exception output
  • Loading branch information
Ken McGrady committed Apr 22, 2021
1 parent 3817741 commit afcf880
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/streamlit/components/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def get(self, path: str) -> None:
component_name = parts[0]
component_root = self._registry.get_component_path(component_name)
if component_root is None:
self.write(f"{path} not found")
self.write("not found")
self.set_status(404)
return

Expand All @@ -327,7 +327,8 @@ def get(self, path: str) -> None:
with open(abspath, "r", encoding="utf-8") as file:
contents = file.read()
except (OSError, UnicodeDecodeError) as e:
self.write(f"{path} read error: {e}")
LOGGER.error(f"ComponentRequestHandler: GET {path} read error", exc_info=e)
self.write("read error")
self.set_status(404)
return

Expand Down
2 changes: 1 addition & 1 deletion lib/streamlit/server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def validate_absolute_path(self, root, absolute_path):
media_file_manager.get(absolute_path)
except KeyError:
LOGGER.error("MediaFileManager: Missing file %s" % absolute_path)
raise tornado.web.HTTPError(404, "%s not found", absolute_path)
raise tornado.web.HTTPError(404, "not found")

return absolute_path

Expand Down
6 changes: 3 additions & 3 deletions lib/tests/streamlit/components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def test_invalid_component_request(self):

response = self._request_component("invalid_component")
self.assertEqual(404, response.code)
self.assertEqual(b"invalid_component not found", response.body)
self.assertEqual(b"not found", response.body)

def test_invalid_content_request(self):
"""Test request failure when invalid content (file) is provided."""
Expand All @@ -425,7 +425,7 @@ def test_invalid_content_request(self):

self.assertEqual(404, response.code)
self.assertEqual(
b"components_test.test read error: Invalid content",
b"read error",
response.body,
)

Expand All @@ -443,7 +443,7 @@ def test_invalid_encoding_request(self):

self.assertEqual(404, response.code)
self.assertEqual(
b"components_test.test read error: 'utf-8' codec can't decode bytes in position 9-10: unexpected end of data",
b"read error",
response.body,
)

Expand Down

0 comments on commit afcf880

Please sign in to comment.