# -*- coding: utf-8 -*-
from setuptools 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.6',
    'description': 'A 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\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\nParsing error messages generated by DRF is a bit of pain for client developers. They need to try-catch different possible error formats. When you add errors raised at the business logic level, the error parsing becomes even more difficult. \n\nThis package unifies the output format of DRF in the "Hipo Error Protocol". \n\n*No more "An error occured." errors.*\n\nThis package also provides the "fallback message", a text string that always contains a human readable error summary. This way, client developers can always fallback and show this message when the client receives an error that is not handled.\n\n> Sounds cool! Can client devs just use this field all the time?\n\nIn our past experience, we noticed that some _lazy_ client developers tend to use this message and avoid writing any code to parse the error bundle. However, the message in this field is automatically generated and may not always be suitable for end users. In order to make clear that this is a *fallback*  message, we named this field "fallback_message"\n\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Client SDKs](#client-sdks)\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\nYou can make 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 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## Settings\nYou can set default key for Django\'s non field errors key (it is `"__all__"`) by adding this to your Django settings:\n\n```\nHIPO_DRF_EXCEPTIONS_SETTINGS = {\n    "DJANGO_NON_FIELD_ERRORS_KEY": "field_free_errors"  # by default it\'s "non_field_errors" to be consistent with DRF.\n}\n```\n\n## Client SDKs\n\nWe have SDKs for client side.\n\n- [`hipo-exceptions-js`](https://github.com/Hipo/hipo-exceptions-js) is for JS.\n- [`hipo-exceptions-android`](https://github.com/Hipo/hipo-exceptions-android) is for Android.\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',
    'maintainer': None,
    'maintainer_email': None,
    '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)
