# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['hipo_drf_exceptions']

package_data = \
{'': ['*']}

install_requires = \
['Django>=1.8', 'djangorestframework>=3.0']

setup_kwargs = {
    'name': 'hipo-drf-exceptions',
    'version': '0.1.0',
    'description': 'An Django app for returning consistent, verbose and easy to parse error messages on Django Rest Framework backends.',
    'long_description': '# Hipo DRF Exceptions\n[![hipo](https://img.shields.io/badge/hipo-red.svg)](https://hipolabs.com) [![Build Status](https://travis-ci.org/Hipo/hipo-drf-exceptions.svg?branch=master)](https://travis-ci.org/Hipo/hipo-drf-exceptions) [![pypi](https://img.shields.io/pypi/v/hipo-drf-exceptions.svg)](https://pypi.org/project/hipo-drf-exceptions/)\n\n\nA [Django](https://www.djangoproject.com) app for returning consistent, verbose and easy to parse error messages on [Django Rest Framework](https://www.django-rest-framework.org/) backends.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Support](#support)\n- [Contributing](#contributing)\n\n## Installation\n\nYou can get stable version of Hipo Excepitons by using pip, pipenv or poetry:\n```\npip install hipo-drf-exceptions\n```\n\n## Usage\n\n### Handler\nYou will need to set `EXCEPTION_HANDLER` of the `REST_FRAMEWORK` setting of your Django project settings.py file.\n```\nREST_FRAMEWORK = {\n    ..\n    \'EXCEPTION_HANDLER\': \'hipo_drf_exceptions.handler\',\n}\n```\n\n### Example Error Responses\n\n#### Field Error\n\nHave validations on model level and raise `ValidationError` when it is required.\n```python\nfrom django.core.exceptions import ValidationError\n\nclass Invitation(models.Model):\n    email = models.EmailField(unique=True)\n\n    def save(self, *args, **kwargs):\n        if User.objects.filter(email=self.email).exists():\n            raise ValidationError({"email": _("Email is already registered.")})\n            \n        super().save(*args, **kwargs)\n```\n\nIf the view or serializer encounters with the `ValidationError`, The response will be like:\n```json\n{\n    "type": "ValidationError",\n    "detail": {\n        "email": [\n            "Email is already registered."\n        ]\n    },\n    "fallback_message": "\'email\' has an error. Email is already registered."\n}\n```\n\n#### Non Field Error\nImplement your own error classes.\n```python\nfrom hipo_drf_exceptions import BaseAPIException\n\nclass ProfileCredentialError(BaseAPIException):\n    default_detail = _(\'Profile credentials are not correct.\')\n```\n\nRaise error when it is required.\n```python\nclass AuthenticationView(GenericAPIView):\n\n    def post(self, request, *args, **kwargs):\n        ..\n        if not profile.check_password(password):\n            raise ProfileCredentialError()\n        ..\n```\n\nThe response will be like:\n```json\n{\n    "type": "ProfileCredentialError",\n    "detail": {\n        "non_field_errors": [\n            "Profile credentials are not correct."\n        ]\n    },\n    "fallback_message": "Profile credentials are not correct."\n}\n```\n\n## Support\n\nPlease [open an issue](https://github.com/hipo/hipo-drf-exceptions/issues/new) for support.\n\n## Contributing\n\nPlease contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/hipo/hipo-drf-exceptions/compare/).\n',
    'author': 'Hipo',
    'author_email': 'pypi@hipolabs.com',
    'url': 'https://github.com/hipo/hipo-drf-exceptions',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=2.7',
}


setup(**setup_kwargs)
