How to use the arxiv.status.HTTP_500_INTERNAL_SERVER_ERROR function in arxiv

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-search / search / controllers / tests.py View on Github external
def test_index_is_down(self, mock_index):
        """Test returns 'DOWN' + status 500 when index raises an exception."""
        mock_index.search.side_effect = RuntimeError
        response, status_code, _ = health_check()
        self.assertEqual(response, 'DOWN', "Response content should be DOWN")
        self.assertEqual(status_code, status.HTTP_500_INTERNAL_SERVER_ERROR,
                         "Should return 500 status code.")
github arXiv / arxiv-search / search / controllers / tests.py View on Github external
def test_index_returns_no_result(self, mock_index):
        """Test returns 'DOWN' + status 500 when index returns no results."""
        mock_index.search.return_value = dict(metadata={}, results=[])
        response, status_code, _ = health_check()
        self.assertEqual(response, 'DOWN', "Response content should be DOWN")
        self.assertEqual(status_code, status.HTTP_500_INTERNAL_SERVER_ERROR,
                         "Should return 500 status code.")
github arXiv / arxiv-browse / tests / test_exceptions.py View on Github external
def test_500(self, mock_abs):
        """A 500 response should be returned."""
        # Raise a general exception from the get_abs_page controller.
        mock_abs.side_effect = AbsException

        """Disable logging to avoid messy output during testing"""
        self.app.logger.disabled = True

        with self.assertRaises(AbsException):
            response = self.client.get('/abs/1234.5678')
            self.assertEqual(response.status_code,
                             status.HTTP_500_INTERNAL_SERVER_ERROR)
            self.assertIn('text/html', response.content_type)
github arXiv / arxiv-search / tests / test_exceptions.py View on Github external
def test_index_connection_error(self, mock_search):
        """When an IndexConnectionError occurs, an error page is displayed."""
        mock_search.side_effect = IndexConnectionError
        response = self.client.get('/?searchtype=title&query=foo')
        self.assertEqual(response.status_code,
                         status.HTTP_500_INTERNAL_SERVER_ERROR)
        self.assertIn('text/html', response.content_type)
github arXiv / arxiv-search / search / controllers / __init__.py View on Github external
Search result response data.
    int
        HTTP status code.
    dict
        Headers to add to the response.

    """
    try:
        document_set = index.SearchSession.search(  # type: ignore
            SimpleQuery(search_field="all", value="theory")
        )
    except Exception:
        return "DOWN", status.HTTP_500_INTERNAL_SERVER_ERROR, {}
    if document_set["results"]:
        return "OK", status.HTTP_200_OK, {}
    return "DOWN", status.HTTP_500_INTERNAL_SERVER_ERROR, {}
github arXiv / arxiv-search / search / routes / api / exceptions.py View on Github external
def handle_internal_server_error(error: InternalServerError) -> Response:
    """Render the base 500 error page."""
    if isinstance(error, HTTPException):
        rendered = jsonify({'code': error.code, 'error': error.description})
    else:
        logger.error('Caught unhandled exception: %s', error)
        rendered = jsonify({'code': status.HTTP_500_INTERNAL_SERVER_ERROR,
                            'error': 'Unexpected error'})
    response: Response = make_response(rendered)
    response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    return response
github arXiv / arxiv-search / search / routes / api / exceptions.py View on Github external
def handle_internal_server_error(error: InternalServerError) -> Response:
    """Render the base 500 error page."""
    if isinstance(error, HTTPException):
        rendered = jsonify({'code': error.code, 'error': error.description})
    else:
        logger.error('Caught unhandled exception: %s', error)
        rendered = jsonify({'code': status.HTTP_500_INTERNAL_SERVER_ERROR,
                            'error': 'Unexpected error'})
    response: Response = make_response(rendered)
    response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    return response