diff --git a/src/marqo/tensor_search/api.py b/src/marqo/tensor_search/api.py index 75320fe45..4c9d83fef 100644 --- a/src/marqo/tensor_search/api.py +++ b/src/marqo/tensor_search/api.py @@ -83,9 +83,6 @@ def marqo_base_exception_handler(request: Request, exc: base_exceptions.MarqoErr # Base exceptions (base_exceptions.InternalError, api_exceptions.InternalError), (base_exceptions.InvalidArgumentError, api_exceptions.InvalidArgError), - - # If no mapping is found, raise a generic API error (500) - (base_exceptions.MarqoError, api_exceptions.MarqoWebError), ] converted_error = None @@ -95,8 +92,9 @@ def marqo_base_exception_handler(request: Request, exc: base_exceptions.MarqoErr break # Completely unhandled exception (500) + # This should abstract away internal error. if not converted_error: - converted_error = api_exceptions.MarqoWebError(exc.message) + converted_error = api_exceptions.MarqoWebError("Marqo encountered an unexpected internal error.") return marqo_api_exception_handler(request, converted_error) diff --git a/tests/tensor_search/test_api_exception_handler.py b/tests/tensor_search/test_api_exception_handler.py index 3a727be63..ec58d65fe 100644 --- a/tests/tensor_search/test_api_exception_handler.py +++ b/tests/tensor_search/test_api_exception_handler.py @@ -89,3 +89,13 @@ def test_base_exception_handler_vespa_errors(self, mock_api_exception_handler): with self.subTest("Vespa error: Vespa Error"): marqo_base_exception_handler(self.normal_request, vespa_exceptions.VespaError(self.generic_error_message)) assert isinstance(mock_api_exception_handler.call_args_list[-1][0][1], api_exceptions.MarqoWebError) + + @mock.patch("marqo.tensor_search.api.marqo_api_exception_handler") + def test_base_exception_handler_unhandled_error(self, mock_api_exception_handler): + # Ensure that an unhandled error is converted to a MarqoWebError and the original message is not propagated + marqo_base_exception_handler(self.normal_request, base_exceptions.MarqoError("This should not be propagated.")) + converted_error = mock_api_exception_handler.call_args_list[-1][0][1] + + self.assertIsInstance(converted_error, api_exceptions.MarqoWebError) + self.assertNotIn("This should not be propagated.", converted_error.message) + self.assertIn("unexpected internal error", converted_error.message) \ No newline at end of file