Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlaszczuk committed Apr 14, 2016
2 parents 5d49aa7 + dfee021 commit 3135159
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Tomasz Łaszczuk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE readme.rst
6 changes: 3 additions & 3 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ into
"message" : "This field may not be blank."
},
{
"age" : 2023,
"code" : 2023,
"field" : "age",
"message" : "This field may not be null."
},
{
"age" : 2041,
"code" : 2041,
"field" : "description",
"message" : "Ensure this field has no more than 100 characters."
},
Expand Down Expand Up @@ -340,4 +340,4 @@ Pull requests won't be accepted without passing tests. You can run the test suit
python runtests.py
.. _Django Rest framework: http://django-rest-framework.org/
.. _Django Rest framework: http://django-rest-framework.org/
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
4 changes: 3 additions & 1 deletion rest_framework_friendly_errors/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def get_field_kwargs(self, field, field_data):
kwargs.update({'input': field_data,
'input_type': type(field_data).__name__})
elif field_type in self.field_map['file']:
kwargs.update({'max_length': field.max_length}),
kwargs.update({'max_length': field.max_length,
'length': len(field.parent.data.get(
field.source, ''))})
elif field_type in self.field_map['composite']:
kwargs.update({'input_type': type(field_data).__name__})
elif field_type in self.field_map['relation']:
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def get_package_data(package):
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
Expand Down

0 comments on commit 3135159

Please sign in to comment.