Skip to content

Commit e815d8d

Browse files
committed
Clenup unhandled exc
1 parent 35bc3af commit e815d8d

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

drf_simple_api_errors/exception_handler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import logging
2+
from typing import Optional
23

34
from rest_framework import exceptions
45
from rest_framework.response import Response
56
from rest_framework.views import set_rollback
67

78
from drf_simple_api_errors import formatter, handlers
8-
from drf_simple_api_errors.exceptions import ServerError
99
from drf_simple_api_errors.types import ExceptionHandlerContext
1010

1111
logger = logging.getLogger(__name__)
1212

1313

14-
def exception_handler(exc: Exception, context: ExceptionHandlerContext) -> Response:
14+
def exception_handler(
15+
exc: Exception, context: ExceptionHandlerContext
16+
) -> Optional[Response]:
1517
"""
1618
Custom exception handler for DRF.
1719
@@ -44,10 +46,7 @@ def exception_handler(exc: Exception, context: ExceptionHandlerContext) -> Respo
4446
# This is because it's not good practice to expose the details of
4547
# unhandled exceptions to the client.
4648
if not isinstance(exc, exceptions.APIException):
47-
# Raise a ServerError exception instead of returning None, because
48-
# we can control the response format this way.
49-
logger.info("Server error (500) from unexpected exception.", exc_info=True)
50-
return ServerError
49+
return None
5150

5251
# Get the API response headers from the exception.
5352
headers = handlers.get_response_headers(exc)

drf_simple_api_errors/exceptions.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/test_exception_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pytest
66

7-
from drf_simple_api_errors import exceptions
87
from drf_simple_api_errors.exception_handler import exception_handler
98
from tests.utils import render_response
109

@@ -408,4 +407,4 @@ def test_unexpected_exception(self, mocker):
408407
"""
409408
exc = Exception("Unexpected error")
410409
response = exception_handler(exc, mocker.Mock())
411-
assert response is exceptions.ServerError
410+
assert response is None

0 commit comments

Comments
 (0)