mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 23:37:18 +00:00
do not write anything on httpexceptions in log
This commit is contained in:
parent
6becd01803
commit
bee97df87f
@ -18,7 +18,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
from aiohttp.web import middleware, Request
|
from aiohttp.web import middleware, Request
|
||||||
from aiohttp.web_exceptions import HTTPClientError
|
from aiohttp.web_exceptions import HTTPException
|
||||||
from aiohttp.web_response import StreamResponse
|
from aiohttp.web_response import StreamResponse
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ def exception_handler(logger: Logger) -> MiddlewareType:
|
|||||||
async def handle(request: Request, handler: HandlerType) -> StreamResponse:
|
async def handle(request: Request, handler: HandlerType) -> StreamResponse:
|
||||||
try:
|
try:
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
except HTTPClientError:
|
except HTTPException:
|
||||||
raise
|
raise # we do not raise 5xx exceptions actually so it should be fine
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("exception during performing request to %s", request.path)
|
logger.exception("exception during performing request to %s", request.path)
|
||||||
raise
|
raise
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiohttp.web_exceptions import HTTPBadRequest
|
from aiohttp.web_exceptions import HTTPBadRequest, HTTPNoContent
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
@ -21,6 +21,20 @@ async def test_exception_handler(mocker: MockerFixture) -> None:
|
|||||||
logging_mock.assert_not_called()
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_exception_handler_success(mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must pass client exception
|
||||||
|
"""
|
||||||
|
request = pytest.helpers.request("", "", "")
|
||||||
|
request_handler = AsyncMock(side_effect=HTTPNoContent())
|
||||||
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
|
handler = exception_handler(logging.getLogger())
|
||||||
|
with pytest.raises(HTTPNoContent):
|
||||||
|
await handler(request, request_handler)
|
||||||
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
async def test_exception_handler_client_error(mocker: MockerFixture) -> None:
|
async def test_exception_handler_client_error(mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must pass client exception
|
must pass client exception
|
||||||
|
Loading…
Reference in New Issue
Block a user