Skip to content

Commit

Permalink
Merge pull request FutureMind#3 from oasiswork/feature-add-catch-all-…
Browse files Browse the repository at this point in the history
…exception

Add settings to catch all exception as friendly errors
  • Loading branch information
tomlaszczuk committed Apr 14, 2016
2 parents a0959e6 + f12120d commit ab40b74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rest_framework_friendly_errors/handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework.views import exception_handler
from rest_framework.exceptions import APIException

from rest_framework_friendly_errors import settings
from rest_framework_friendly_errors.utils import is_pretty
Expand All @@ -7,6 +8,10 @@
def friendly_exception_handler(exc, context):
response = exception_handler(exc, context)

if not response and settings.CATCH_ALL_EXCEPTIONS:
exc = APIException(exc)
response = exception_handler(exc, context)

if response is not None:
if is_pretty(response):
return response
Expand Down
3 changes: 3 additions & 0 deletions rest_framework_friendly_errors/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
VALIDATION_FAILED_MESSAGE = USER_SETTINGS.get('VALIDATION_FAILED_MESSAGE',
_('Validation Failed'))

CATCH_ALL_EXCEPTIONS = USER_SETTINGS.get(
'CATCH_ALL_EXCEPTIONS', False)

FRIENDLY_FIELD_ERRORS = {
'BooleanField': {'required': 2001, 'invalid': 2011, 'null': 2021},
'NullBooleanField': {'required': 2001, 'invalid': 2011, 'null': 2021},
Expand Down

0 comments on commit ab40b74

Please sign in to comment.