{"id":20509261,"url":"https://github.com/futuremind/drf-friendly-errors","last_synced_at":"2025-06-29T22:35:45.043Z","repository":{"id":47720888,"uuid":"51290556","full_name":"FutureMind/drf-friendly-errors","owner":"FutureMind","description":"Extension for Django REST framework error display","archived":false,"fork":false,"pushed_at":"2024-03-08T09:15:10.000Z","size":45,"stargazers_count":129,"open_issues_count":9,"forks_count":58,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-12-10T17:49:40.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FutureMind.png","metadata":{"files":{"readme":"readme.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-08T10:07:26.000Z","updated_at":"2024-11-05T22:22:43.000Z","dependencies_parsed_at":"2023-01-31T01:15:17.616Z","dependency_job_id":null,"html_url":"https://github.com/FutureMind/drf-friendly-errors","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureMind%2Fdrf-friendly-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureMind%2Fdrf-friendly-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureMind%2Fdrf-friendly-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureMind%2Fdrf-friendly-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FutureMind","download_url":"https://codeload.github.com/FutureMind/drf-friendly-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230394228,"owners_count":18218707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T20:23:38.898Z","updated_at":"2024-12-19T07:06:53.798Z","avatar_url":"https://github.com/FutureMind.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"DRF Friendly Errors\n===================\n\n**Extension for Django REST framework error display**\n\nOverview\n--------\n\nThis package extends default error JSON body providing configurable error codes\nand more consumable response structure.\n\nIt turns default JSON body of HTTP 400 response, which look like this\n\n.. code:: python\n\n    {\n        \"name\": [\"This field is required.\"],\n        \"password\": [\"This field may not be blank.\"]\n        \"age\": [\"This field may not be null.\"]\n        \"description\": [\"Ensure this field has no more than 100 characters.\"]\n    }\n\ninto\n\n.. code:: python\n\n    {\n        \"code\" : 1001,\n        \"message\" : \"Validation Failed\",\n        \"errors\" : [\n            {\n                \"code\" : 2002,\n                \"field\" : \"name\",\n                \"message\" : \"This field is required.\"\n            },\n            {\n                \"code\" : 2031,\n                \"field\" : \"password\",\n                \"message\" : \"This field may not be blank.\"\n            },\n            {\n                \"code\" : 2023,\n                \"field\" : \"age\",\n                \"message\" : \"This field may not be null.\"\n            },\n            {\n                \"code\" : 2041,\n                \"field\" : \"description\",\n                \"message\" : \"Ensure this field has no more than 100 characters.\"\n            },\n        ]\n    }\n\nLibrary handles all `Django REST framework`_ built-in serializer validation.\n\nRequirements\n------------\n-  Python (2.7, 3.4)\n-  Django (1.8, 1.9)\n-  Django REST framework (3.3)\n\nInstallation\n------------\n\nBy running installation script\n\n.. code:: bash\n\n    $ python setup.py install\n\nOr using pip\n\n.. code:: bash\n\n    $ pip install drf-friendly-errors\n\nUsage\n-----\n\nSimply add a FriendlyErrorMessagesMixin to your serializer or model serializer class\n\n.. code:: python\n\n    from rest_framework_friendly_errors.mixins import FriendlyErrorMessagesMixin\n\n    class MySerializer(FriendlyErrorMessagesMixin, ModelSerializer):\n\nIf you want to change default library settings and provide your own set of error codes just add following in your\nsettings.py\n\n.. code:: python\n\n    FRIENDLY_ERRORS = {\n        FIELD_ERRORS = {\n            'CharField': {'required': 10, 'null':11, 'blank': 12, 'max_length': 13, 'min_length': 14}\n        }\n        VALIDATOR_ERRORS = {\n            'UniqueValidator': 50\n        },\n        EXCEPTION_DICT = {\n            'PermissionDenied': 100\n        }\n    }\n\nCustom serializer validation\n----------------------------\n\nIf you need custom field validation or validation for whole serializer register your validation in serializer class\n\n.. code:: python\n\n    class PostSerializer(FriendlyErrorMessagesMixin,\n                         serializers.ModelSerializer):\n        class Meta:\n            model = Post\n\n        def validate_title(self, value):\n            if value[0] != value[0].upper():\n                raise ValidationError('First letter must be an uppercase')\n            return value\n\n        def validate(self, attrs):\n            category = attrs.get('category)\n            title = attrs.get('title')\n            if category and category not in title:\n                raise ValidationError('Title has to include category')\n            return attrs\n\n        FIELD_VALIDATION_ERRORS = {'validate_title': 5000} # register your own validation method and assign it to error code\n        NON_FIELD_ERRORS = {'Title has to include category': 8000} # register non field error messages and assign it to error code\n\nIf you want to raise field error in validate method use register_error method provided by a mixin\n\n.. code:: python\n\n    class PostSerializer(FriendlyErrorMessagesMixin,\n                         serializers.ModelSerializer):\n        class Meta:\n            model = Post\n\n        def validate(self, attrs):\n            category = attrs.get('category')\n            title = attrs.get('title')\n            if category and category not in title:\n                self.register_error(error_message='Title has to include category',\n                                    error_code=8000,\n                                    field_name='title')\n            return attrs\n\nError codes not related to serializer validation\n------------------------------------------------\n\nTo turn other type of errors responses into friendly errors responses with error codes\nadd this exception handler to your REST_FRAMEWORK settings\n\n.. code:: python\n\n    REST_FRAMEWORK = {\n        'EXCEPTION_HANDLER':\n        'rest_framework_friendly_errors.handlers.friendly_exception_handler'\n    }\n\nDefault error codes\n-------------------\n\nFollowing conventions were used:\n\n1xxx - Are reserved for non field errors\n\n2xxx - Are reserved for field errors\n\n3xxx - Are reserved for validator errors\n\n4xxx - Are reserved for other errors not related to serializer validation\n\nDefault field error codes\n-------------------------\n\nField is required\n\n- 2001: BooleanField, NullBooleanField\n- 2002: CharField, EmailField, RegexField, SlugField, URLField, UUIDField, FilePathField, IPAddressField\n- 2003: IntegerField, FloatField, DecimalField\n- 2004: ChoiceField, MultipleChoiceField\n- 2005: FileField, ImageField\n- 2006: ListField, DictField, JSONField\n- 2007: StringRequiredField, PrimaryKeyRelatedField, HyperlinkedRelatedField, SlugRelatedField, HyperlinkedIdentityField, ManyRelatedField\n- 2008: ReadOnlyField, HiddenField, ModelField, SerializerMethodField\n\nField data is invalid (invalid regex, string instead of number, date, etc.)\n\n- 2011: BooleanField, NullBooleanField\n- 2012: EmailField, RegexField, SlugField, URLField, UUIDField, IPAddressField\n- 2013: IntegerField, FloatField, DecimalField\n- 2014: FileField, ImageField\n- 2015: DateTimeField, DateField, TimeField, DurationField\n\nField data cannot be null\n\n- 2021: BooleanField, NullBooleanField\n- 2022: CharField, EmailField, RegexField, SlugField, URLField, UUIDField, FilePathField, IPAddressField\n- 2023: IntegerField, FloatField, DecimalField\n- 2024: ChoiceField, MultipleChoiceField\n- 2025: FileField, ImageField\n- 2026: ListField, DictField, JSONField\n- 2027: StringRequiredField, PrimaryKeyRelatedField, HyperlinkedRelatedField, SlugRelatedField, HyperlinkedIdentityField, ManyRelatedField\n- 2028: ReadOnlyField, HiddenField, ModelField, SerializerMethodField\n\nField data cannot be blank\n\n- 2031: CharField, EmailField, RegexField, SlugField, URLField, UUIDField, IPAddressField\n\nField data is too long string\n\n- 2041: CharField, EmailField, RegexField, SlugField, URLField, UUIDField, IPAddressField\n- 2042: IntegerField, FloatField, DecimalField\n- 2043: FileField, ImageField\n\nField data is too short string\n\n- 2051: CharField, EmailField, RegexField, SlugField, URLField, UUIDField, IPAddressField\n\nField data is too big number\n\n- 2061: IntegerField, FloatField, DecimalField\n\nField data is too small number\n\n- 2071: IntegerField, FloatField, DecimalField\n\nField data do not match any value from available choices\n\n- 2081: ChoiceField, MultipleChoiceField\n- 2082: FilePathField\n- 2083: ManyRelatedField\n\nField is empty\n\n- 2091: FileField, ImageField\n- 2092: MultipleChoiceField\n- 2093: ManyRelatedField\n\nFile has no name\n\n- 2101: FileField, ImageField\n\nFile is an invalid image\n\n- 2111: ImageField\n\nField is not a list\n\n- 2121: MultipleChoiceField\n- 2122: ListField\n- 2123: ManyRelatedField\n\nField is not a dict\n\n- 2131: DictField\n\nField is not a json\n\n- 2141: JSONField\n\nField does not exist (invalid hyperlink, primary key, etc.)\n\n- 2151: PrimaryKeyRelatedField, HyperlinkedRelatedField, SlugRelatedField, HyperlinkedIdentityField\n\nIncorrect type for relation key\n\n- 2161: PrimaryKeyRelatedField, HyperlinkedRelatedField, SlugRelatedField, HyperlinkedIdentityField\n\nCouldn't match url or name to a view\n\n- 2171: HyperlinkedRelatedField, HyperlinkedIdentityField\n\nExpected a DateTime, got Date\n\n- 2181: DateTimeField\n\nExcpected a Date, got DateTime\n\n- 2191: DateField\n\nToo many digits for defined Decimal\n\n- 2201: DecimalField\n\nToo many whole digits for defined Decimal\n\n- 2211: DecimalField\n\nToo many decimal digits for defined Decimal\n\n- 2221: DecimalField\n\nDefault built-in validators error codes\n---------------------------------------\n\n- UniqueValidator: 3001\n- UniqueTogetherValidator: 3003\n- UniqueForDateValidator: 3004\n- UniqueForMonthValidator: 3004\n- UniqueForYearValidator: 3005\n- RegexValidator: 3006\n- EmailValidator: 3007\n- URLValidator: 3008\n- MaxValueValidator: 3009\n- MinValueValidator: 3010\n- MaxLengthValidator: 3011\n- MinLengthValidator: 3012\n- DecimalValidator: 3013\n- validate_email: 3014\n- validate_slug: 3015\n- validate_unicode_slug: 3016\n- validate_ipv4_address: 3017\n- validate_ipv46_address: 3018\n- validate_comma_separated_integer_list: 3019\n- int_list_validator: 3020\n\nOther error codes not related to serializer validation\n------------------------------------------------------\n- Server Error: 4000\n- Parser Error (exception was raised by Parser class): 4001,\n- Authentication Failed (invalid credentials were provided): 4002,\n- Not Authenticated (no credentials were provided): 4003,\n- Not Found: 4004,\n- Permission Denied: 4005,\n- Method Not Allowed (invalid HTTP method): 4006,\n- Not Acceptable (Could not satisfy the request Accept header): 4007,\n- Unsupported Media-Type: 4008,\n- Throttled (Too many requests): 4009\n\nTests\n-----\n\nPull requests won't be accepted without passing tests. You can run the test suite with:\n\n.. code:: python\n\n    python runtests.py\n\n.. _Django Rest framework: http://django-rest-framework.org/\n\nContributors\n------------\n- toxinu","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturemind%2Fdrf-friendly-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturemind%2Fdrf-friendly-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturemind%2Fdrf-friendly-errors/lists"}